Im sure we can lay out allot of possibilities, but that's not what u
want.

There are two possible reasons for the fact that u would like to
instantiate a class runtime (via createChild):

1. U want your main application to be as light as possible.
2. U don't know (at compile time) which class will represent the child.


My guess is that number 2 is the one u are after. To achieve that goal
take the following steps.


A.
Place the following code inside your initialize function in your main
application:

Components;

B.
Create (in the same dir as the main application) a 'Components.as' file,
this file contains the following code:

class Components
{
        public function Components()
        {
                //put all possible children inhere
                com.myProject.MyClass;
        };
};


The above two steps make sure the possible childs are included in the
flex application (they are compiled in the resulting swf).


C.
Create a function in your application that looks like this:

public function getClassRef(classPath_str:String):Object
{
        var classRef_obj:Object = _global;
        var class_array:Array = classPath_str.split(".");
        
        for (var i = 0; i < class_array.length; i++)
        {
                classRef_obj = classRef_obj[class_array[i]];
        };

        return classRef_obj;
};

D.
In the initialize function u can create a child like this:

baseContainer.createChild(getClassRef("com.myProject.MyClass"));


I hope this helps :)

Greetz Erik



-----Original Message-----
From: Scott Barnes [mailto:[EMAIL PROTECTED] 
Sent: woensdag 6 april 2005 13:55
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] Re: createChild dynamically via DB arguments..


Heres a test for yas:

Inside a new FLEX app directory (ie start fresh), create a dir, then
inside that dir, create another and another (go as deep as ya want),
then finally create a mxml file.

Then create an simple class file, and instantiate it via initialize() on
mx.Application, then inside this class, do the same as you did (make as
many nested ones as you want if need be) then at some point, simply do
this

mx.core.Application.application.baseContainer.createChild(blah[arg1][arg
2]
etc..)

Then explain if you can / want to, how the hell that works. As I must be
dumber then originally thought as i can't seem to connect the dots on
how the hell that works? hell i'm struggling to even explain it....
(also i put another sequence of the above inside the
unknown-loaded-at-runtime-class and they came up aswell heh).

imho its as if at compile time, the entire app is packaged together, and
seperated into whats FLASH code and whats other, if other do i embed it
inside the swf and all that... i''ll pop the hood a later day (if i can
figure it out) but *shrug* my level of FLEX expertises ends here hehehe.

_level0["com"] or _global["com"] etc  won't work. As well as
findClass();

On a side note/question. I am also unsure if (hell i have no idea to
test) whether or not if you have assets embedded inside the mxml files
in question (even declared as RSL) will they request a new asset per
instantiation...

Any input / help is most welcomed heh.





 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to