-
randomcodescraps posted this
AS3 Library Linkage Class
So, you have a symbol on the library and you want to use it on your class files. You can sure use the new atribute and add to the Display List, but some of OOP Encapsulation will be lost, once the object is not on your packages but stored on the library. I personally like to use the undocumented function getDefinitionByName to get library symbols. The thing is, the implementation of getDefinitionByName always confuses me, and perhaps confuses you too, so i build a simple wrapper class to abstract this and return the library symbol with only one method. Enjoy.
package com.guinetik.kinetic.utils
{
import flash.display.BitmapData;
import flash.display.DisplayObject;
import flash.display.Sprite;
import flash.utils.getDefinitionByName;
public class Linkage
{
public static function getLibrarySymbol(linkage:String):DisplayObject
{
var c :Class = getDefinitionByName(linkage) as Class;
var obj :DisplayObject = new c() as DisplayObject;
return obj;
}
public static function getLibraryImage(linkage:String):BitmapData
{
var c :Class = getDefinitionByName(linkage) as Class;
var obj :BitmapData = new c(0, 0) as BitmapData;
return obj;
}
public static function addToComponent():void
{
trace("Initialized Kinetic");
}
}
}