Posted by driverjase on March 31, 2007 at 09:47 PM
Keith Peters had a couple of posts a little while ago about embedding assets in as3 (1 and 2). One thing that came up in both of them that could not be resolved was how to associate a custom class with an embedded symbol. The example given was:
...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
I was trying to do the same thing and found out that there actually is a way to do this. Instead of adding the embed tag above a variable like so:
package
{
import flash.display.Sprite;
public class Application extends Sprite
{
[Embed(source="library.swf", symbol="Star")]
private var Star:Class;
public function Application()
{
var star:Sprite = new Star();
addChild(star);
}
}
}...which only allows you to type it as Sprite or MovieClip. You can instead create the Star class and add the embed tag directly above the class declaration:
package
{
import flash.display.*;
[Embed(source="library.swf", symbol="Star")]
public class Star extends Sprite
{
public function Star()
{
}
}
}and implement it in the main class with:
package
{
import flash.display.Sprite;
public class Application extends Sprite
{
private var star:Star;
public function Application()
{
star = new Star();
addChild(star);
}
}
}Now you have a custom Star class you can do anything you want with associated with an embedded asset!
Yay! Problem solved.

Here's an example that uses a few Flash symbol assets this way. Source code at the bottom, don't need to read.
http://www.jessewarden.com/archives/2006/12/integrating_a_f.html
Posted by: JesterXL at March 31, 2007 10:52 PM