You do not need to “download” them, they are built-in. You just need to create an instance of the images. It is recommended that you have one class that manages shared resources:
public class TextureAssets { [Embed(source = "../lib/ball1.png")] private static var Ball1:Class; [Embed(source = "../lib/ball2.png")] private static var Ball2:Class; public static var ball1Texture:BitmapData; public static var ball2Texture:BitmapData; public static function init():void { ball1Texture = (new Ball1() as Bitmap).bitmapData; ball2Texture = (new Ball2() as Bitmap).bitmapData; }
Then you call TextureAssets.init() once (e.g. in Main.as) and when you need bitmapData: use new Bitmap(TextureAssets.ball1Texture)
Thus, your program requires only the memory needed for one bitmapData, instead of having many that end in the same.
If you need to perform operations on bitmapData, keeping the original, you can use:
var modified:bitmapData = TextureAssets.ballTexture.clone();
Also, if you create all the images of balls from the same class, it is recommended to refuse static access and instead initialize bitmapDatas in the constructor, create a new TextureAssets () and call the textures through a variable
(access to the static field is slower than direct (.) access: http://jacksondunstan.com/articles/1690 )
source share