AS3 Chronicles #2: Using Embedded Images

Remember in Flash when you wanted to use a simple bitmap? You had to:

  • import the bitmap
  • put it in a new MovieClip
  • give it a unique linkage ID
  • use attachMovie/createObject(v2) on that linkage ID

In Flex 1.5, you had to:

  • use the Embed directive above a variable
  • use createChild/Image.source using the variable

Here’s how you do it in AS3:

[Embed(source="images/Sabin.png")]
var sabin_img:Class;

var img:sabin_img = new sabin_img();
addChild(img);

Crazy!

Peter Elst show’s Chafic Kazoun’s method of using the above to “borrow” a MovieClip from an external SWF. Both of these methods are compile time only.

2 Replies to “AS3 Chronicles #2: Using Embedded Images”

  1. Re-parenting on the fly ffffffffffffffffffffff@*#kin rox :)

    It allows you to have progressive UI (eat as you need) with runtime shared libs in mind…

  2. From what i tested the compiler does not hang when you leave out the square brackets.

    I haven’t gone as far as actually work with the embeded stuff though…

Comments are closed.