Reputation: 221
Is it possible to make an Object that contains a variable of type Bitmap.
what i mean is that i create a Bitmap with bitmapData like this
var swordBitmap:Bitmap = new Bitmap(new Sword_0());
but how do i pass that data into a variable of an Object
Im trying to obtain the Bitmap directly into the Object like this.
public static const SWORD1:Object = { Image:Bitmap = new Bitmap(new Sword_0());, DMG:10, Cost: 50 }
and then somehow to use it like this
var myWeapon:Sprite = new Sprite;
myWeapon.addChild(SWORD1.Image)
or what im doing is not quite right / is not possible.
PS: Sword_0 is the name of the image in the library
Upvotes: 0
Views: 184
Reputation: 2558
Select your bitmap in the library and make sure you select "Export for ActionScript" in the "Actionscript" tab. Give the bitmap a class name and your code will look something like this...
import flash.display.Sprite;
import flash.display.Bitmap;
var struct:Object = {
"bitmap":new Bitmap(new myImg())
}
var mySprite:Sprite = new Sprite();
mySprite.addChild(struct.bitmap);
addChild(mySprite);
Upvotes: 2