AS3 and images; Aching Dreams 2

I upgraded to Flash CS4, and I’ve been working on Aching Dreams 2, as well as simply learning ActionScript 3.0. So far I’m just working on the programming framework; the story, gameplay and characters are still being, ah, fleshed out.

Here’s something interesting I’ve discovered:

When you add an image to a Flash file in the library, it becomes an “embedded asset”. In AS3, you can use the getDefinitionByName() function to find the embedded asset class based on its filename (well, its linkage name, which is by default its filename). Then you can instantiate the class and get a BitmapData class; you can use this to construct a Bitmap class, then use addChild or addChildAt to display it. The really interesting thing is that the documentation says the BitmapData constructor takes a height and width…but this doesn’t seem to matter in the case of embedded assets. Pass the constructor anything you want, even 0,0, and it should still instantiate and display correctly.

EDIT: The followup post has more about this and a better way to pull it off.

One Response to

  1. Gravatar AS3 and images part 2 « Chaos Garden via Pingback:

    [...] Previously I talked about using images in AS3. Now I’ve figured out a further enhancement to the procedure I described. [...]

Leave a Reply »

You must be logged in to post a comment » login.