[AS3] Reflection in ActionScript 3
Today i’ve used reflection for the first time in one of my Flex projects. After some google research i found the correct hint
All you need is the function getDefinitionByName(className:String) found in the flash.utils package. The following 2 lines creates a Class Object of my SampleClass
var className:String = “com.firstrowria.SampleClass”;
var classReference:Class = Class(getDefinitionByName(className));
Now we are ready to get an instance
But there is more. What if we want to call a function of our newly created class? No Problem, even with parameters!
var functionName = “sampleFunction”;
var functionName2 = “sampleFunctionWithParameter”;
classInstance[event.functionName]();
classInstance[event.functionName2](”this is my string parameter”);
firstrow RIA e.U.
Trackbacks & Pingbacks