Dynamic Class importing the proper way

Hi there,

I’m having a trouble of figuring a ‘proper’ easy way of importing classes on runtime. Well, not importing them on runtime(that can’t be done), but using them dynamically.

So far I’ve been importing them manually(typing every one of them for dummy var) but is there any way of doing this automatically?

Sen, I’m counting you will read this and blow my mind away with some neat idea.

Example is based on my projects so far. It’s not very elite way of doing this, but couldn’t figure out any other way:


//First I import the classes from package:
import com.myname.myproject.view.page.*;
 
/*
Then later is same classfile use every page manually, so that flash really uses them and puts them in bytecode, even their are not 'really used' at that time.
The pageClass is just a dummy var to be used.
*/
var pageClass:Home;
var pageClass:News;
var pageClass:Tutors;
 
/*
So now the classes are imported for future dynamic use. Is there any other way to do this? I mean, this way is real pain in the ***. I Wish the .* syntax would be enough, but Flash doesn't import them if not 'used'.
*/
 
/*
Then in some other class or where ever I dynamically take a class into use:
*/
//----
private var __page:Page;
//----
var pageName:String = "classname_here"; 
var pageClass:Page = com.myname.myproject.view.page[pageName];
__page = new pageClass();
 
/*
This is by the way, where the problem is coming with MTASC checking. "com.myname.myproject.view.page[pageName]" is not accepted way of taking a class into use from package, or something.
Error is given as "type error Unkown variable com".
*/

So the ideal solution would be a way to skip the manual ‘using’ of classes for dummy vars, and how should they be used dynamically from package in proper way. So that compile error for example in MTASC checking would not appear.

Cheers,
Ouzo