First off, I’m rather n00b at AS3 so I’m sorry if this is a terrible question. I’ve searched and can’t find direct reference/solution to this exact issue.
My Problem:
I’m trying to embed all my pertinent graphics within a class(“Assets.as”) which will have a static method to retrieve these embedded graphics by name.
What I’ve Tried:
Assets.as
package
{
[...imports...]
public class Assets
{
[Embed(source="assets/images/l_peak.png")]
public static const l_peak:Class;
public static function getByName(pName:String):Bitmap
{
var retClass:Class = flash.utils.getDefinitionByName(pName) as Class;
return new Bitmap(new retClass());
}
}
}
This however returns a null object. Any way I work this, the getDefinitionByName() either returns null or says there isn’t an object named that(i.e. “l_peak”).
I know you can use a loader() to do this dynamically with graphics, but I was hoping to embed these graphics and simply get them dynamically by their name.
Any help would be much appreciated!
Why don’t you try: