BIT-101 [2003-2017]

Update on Embedding Assets in AS3


A few weeks ago, I posted some info on embedding SWF-based assets in AS3.

One question that came up in the comments was how to embed a symbol from a Flash 9 SWF that has a custom class associated with it, and use it as an instance of that custom class. In other words, you create a movie clip in the Flash 9 IDE, give it a class of “Star”, and you have an actual class written, called “Star” that has some functionality that is really cool. Now, you embed that star symbol in your AS3 application, but you can only type it as Sprite or MovieClip. How to get it to be a “Star”?

I finally got to dig in to this a bit more, and sadly, I don’t think there is a way to do this. When you embed a Sprite asset, it comes in as an instance of SpriteAsset, which “is a subclass of the Flash Player’s Sprite class which represents vector graphic images that you embed in a Flex application.”

https://livedocs.macromedia.com/flex/2/langref/mx/core/SpriteAsset.html

Note: “represents vector graphic images”.

Even when I had a real Star class, using describeType, getQualifiedClassName, and getQualifiedSuperclassName show no sign of that class coming though with the embedded object. Any code that should execute from that class does not execute.

In fact, even if you put some code on the timeline of that symbol, say drawing some random lines. It executes fine when compiled in the IDE, but that code will not run in the embedded symbol, pointing up the fact that ALL that is embedded is the vector graphic info.

So, unless I’m missing something, that’s that. The one thing that is kind of odd though, is that if you publish a Flash 8 SWF and then embed an asset from it that has some code in it, it gives you a warning that the AS2 code will be ignored. If all code is discarded anyway, I’m not sure why that warning even exists.

« Previous Post
Next Post »