views:

170

answers:

2

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.
A: 

A class associated with a Flash library asset must be contained within the same SWC.

?

Then, when the SWC is compiled by Flash, it finds the associated class and binds them together?

If this is the case, then artwork and code is coupled together in the same SWC file? I thought Flex w/ SWCs was great because artwork was decoupled...?

EDIT: This is not working. The only way I can instantiate a SWC asset is if it inherits from the base class, so it seems I can't associate custom classes with SWC assets?????!!!!!!

Pup
A: 

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!");
     }

    }

}
grapefrukt
It works! A slight improvement might be `source='/../assets/Assets.swf'` to get at the project root directly. I tried [EMBED] before w/ no success; read that it only works on legacy SWFs. You've made me so happy!
Pup
yeah, that path is a bit hairy, flash develop figures that out automatically for me so i don't need to bother. but the leading slash is a clever way to make it prettier.
grapefrukt