John
John

Reputation: 908

How to load an image in memory with Flex/ActionScript?

So I'm trying to load an embedded image this way:

[Bindable]
[Embed(source="path")]
private var cls_img:Class;

var img:Image = new Image();
img.source = cls_img;

Now I'm trying to copy pixel chunks from it however I get an error that img.bitmapData is null and the error goes away when I add it to the application with addElement(img); Isn't it possible to force flex to load the image in memory so I can manipulate it without adding it to the stage?

Upvotes: 1

Views: 357

Answers (1)

dtuckernet
dtuckernet

Reputation: 7895

Yes - you can use cls_img as a BitmapAsset.

[Bindable]
[Embed(source="path")]
private var cls_img:Class;

...

var asset:BitmapAsset = new cls_img() as BitmapAsset;
// The asset has a bitmapData property that gives you access to the image data
img.source = asset;

For more information, check out the documentation:

http://livedocs.adobe.com/flex/3/html/help.html?content=embed_4.html

Upvotes: 3

Related Questions