I’m back to actionscript after many years in hiatus.
I want to create a loader class that I can use to load class dynamically at runtime. Basically, a factory pattern class.
It will work something like this:
package
{
import runtime_loader;
import app_controller;
import my_error;
public class foo
{
var _controller:app_controller;
public function foo(controller_name:String)
{
_controller = runtime_loader(controller_name);
if (!_controller)
{
throw my_error('fool!')
}
}
}
}
My current runtime_loader class basically has a switch that decides the class to return. I would like to make it as clean as possible. Currently, it looks something like:
switch(name)
{
case 'foobar':
return new foobar;
case 'bezfoo':
return new bezfoo;
default:
return null;
}
It would be sweet if I could do something along the lines of:
try
{
return new $name;
}
catch (invalid_class)
{
...
}
Is there any way to include all the classes that fall under a top level package, even the one in sub packages?
like: import.** ; // I know this is invalid
Any help with creating a factory class would be sweet.