R – An extra wrapper or decorator class needed when using SWC assets

actionscript-3apache-flexflashdevelopflex3

I'm still learning how to compile with the Flex SDK. And I'm learning how to use SWC files and [EMBED] statements to pull my assets into my application.

With the Flash IDE, I can link a library asset to a class and it's automatically embedded into my custom class. So that's 1 asset in 1 class. With the Flex SDK and SWC files, it seems I can only* pull in assets at the variable level, so I end up with my custom classes containing yet another class — this means I have an extra wrapper/decorator (whatever you want to call it) class that I didn't have when using the Flash IDE.

Is this what people typically do? Doesn't that seem superfluous?

  • I've read Colin Moock's 'Essential Actionscript 3.0', where he mentions something about embedding a SWF at class-level as binary data… WTF.

Best Answer

To associate a symbol directly to a class do like this. This works for all kinds of subclasses aswell (as long as they extend the appropriate base class):

package foo {

    import flash.display.Sprite;    

    [Embed(source='../../../../../../assets/Assets.swf', symbol='InfoPopup')]
    public class InfoPopup extends Sprite {

        public function InfoPopup(){
            trace("constructor!");
        }

    }

}
Related Topic