;

PDA

Click to See Complete Forum and Search --> : [F9] Bitmap Loading from Library


iopred
07-21-2006, 10:31 AM
Has anyone figured out a clean way to get Bitmap loading through code in the Flash 9 Alpha?

The embed method that worked in Flex is spitting errors at me, auto-generating a class from the library doesn't want to work, and I really don't think making an MC for every bitmap is the best way around it.

So has anyone had any luck with it? Or should I just chalk it down to it being an Alpha?

Fall_X
07-21-2006, 02:46 PM
Hmmm, I know I've seen this somewhere, but I can't remember where. I'll let you know once I find it again.

jason merchant
07-21-2006, 02:55 PM
I don't know for certain, but if you can't attach the bitmap directly to the display list, you may have to create a sprite through code and attach it to the sprite first. Then you can attach it to the display list. I will check this to see if it works.

Fall_X
07-21-2006, 04:09 PM
Okay, I just did some testing, and here's the deal. I imported a bitmap, and set it to export for as, with an auto-generated class called Test.
If you do var t:Test=new Test(), you get a reference to it, but it extends BitmapData, which isn't a DisplayObject, so you can't just do whatever.addChild(Test). You'll have to create an empty Bitmap, and set it's bitmapData reference to your object. Then you can use that bitmap.

Seems to work fine.

jason merchant
07-21-2006, 04:33 PM
Yeah something like this:

var image:test = new test();
var mysprite:Sprite = new Sprite();
mysprite.graphics.beginBitmapFill(image);
mysprite.graphics.drawRect(0, 0, 100, 100);
mysprite.graphics.endFill();
addChild(mysprite);

Fall_X
07-21-2006, 04:45 PM
Why use beginBitmapFill when you have the Bitmap class for this? Just use :


var image:Test = new Test();
var bmp:Bitmap=new Bitmap();
bmp.bitmapData=image;
this.addChild(bmp);


or, a bit shorter :


var bmp:Bitmap=new Bitmap();
bmp.bitmapData=new Test();
this.addChild(bmp);

iopred
07-21-2006, 08:37 PM
Ah, it's BitmapData *slap*


var bmp:Bitmap = new Bitmap(new Test());
this.addChild(bmp);


Works too, if you guys wanted the quickest way, thanks for the help guys.

Fall_X
07-21-2006, 09:18 PM
Didn't realize you could pass Bitmap a BitmapData object in the constructor, nice. But if you want the shortest way, this is even shorter, lol :

var bmp:Bitmap = this.addChild(new Bitmap(new Test()));

tonypa
08-08-2006, 07:15 AM
Moved to AS3 forum.

scarer
07-18-2007, 02:42 AM
I keep getting the error - Label must be a simple identifier any ideas?

Cheers,

Sarah

jason merchant
07-18-2007, 04:46 AM
What does your code look like?

senocular
07-18-2007, 09:07 AM
You can find an example here:
http://www.senocular.com/flash/tutorials/as3withflashcs3/
download the source files and check the tutorial about half way down page 2.

Note that Flash CS3 has changed this behavior (from Flash 9 alpha) and now requires that the width and height params be used for the new BitmapData instance