I make some game, I use I lot of graphics. I make class that have all graphics for example for menu:
public class MenuGFX
{
[Embed(source = '../../assets/graphics/menu/background.png')]
public static const backgroundGFX:Class;
[Embed(source='../../assets/graphics/menu/startD.png')]
public static const startDGFX:Class;
[Embed(source='../../assets/graphics/menu/startO.png')]
public static const startOGFX:Class;
[Embed(source='../../assets/graphics/menu/startU.png')]
public static const startUGFX:Class;
}
To load graphic from this I use function:
public class GraphicsLoader
{
private static var graphicsDictionary:Dictionary = new Dictionary();
public static function getGraphic(name:String):Bitmap
{
var bitmap:Bitmap = graphicsDictionary[name];
if (bitmap == null)
{
var cls:Object = getDefinitionByName("Graphics::" + name) ;
bitmap = new (cls);
graphicsDictionary[name] = bitmap;
}
return bitmap;
}
}
But this working only when I add manual creating some graphics: private var backgroundBitmap:Bitmap = new MenuGFX.backgroundGFX;
to loader class:
public class GraphicsLoader
{
private static var graphicsDictionary:Dictionary = new Dictionary();
private var backgroundBitmap:Bitmap = new MenuGFX.backgroundGFX;
public static function getGraphic(name:String):Bitmap
{
var bitmap:Bitmap = graphicsDictionary[name];
if (bitmap == null)
{
var cls:Object = getDefinitionByName("Graphics::" + name) ;
bitmap = new (cls);
graphicsDictionary[name] = bitmap;
}
return bitmap;
}
}
I looking for way to avoid making private var someBitmap:Bitmap = new BitmapName;
. Do you know how can I deal with this ?
The class MenuGFX
will not be compiled into your SWF if the class itself is no where referenced / used within your project source code. It should be enough to call new MenuGFX
somewhere in your application (may be in your Main class). The compiler has to know that this class will be used somewhere in your application or it will be ignored.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With