Hi
If you load a module that has a pile of classes in it, you can instantiate them
without having a static reference in your original code. However, you do need
to be a bit cautious.
By default, modules load into a child of Application.currentDomain and thus
aren't as "accessible" as classes loaded directly into
ApplicationDomain.currentDomain.
If you want to create a module or code library that you can load and have
complete access to at runtime as if it's classes were a part of your project
then you need to create a new LoaderContext using
ApplicationDomain.currentDomain and use that LoaderContext to load your module.
Once loaded, you can use a variety of methods to get at the classes. When I do
this I often have the class names as strings in an XML file that I load so I
don't need to do any guessing. I simply look up the class name in the xml, then
use getDefinitionByName(className) as Class and then if that returns a Class I
simply instantiate that class. But then again I'm loading the library into
Application.currentDomain because I intend to use it throughout the project and
have no need to child domain the stuff.
If you put things into an XML file try to avoid a few things like naming a node
or attribute "class", I normally use the attribute "class" but as a consequence
I need to access the attribute using myNode.attribute("class") vs.
myno...@class since @class will fail because "class" is a reserved word and
Flex no like that. I'm stuborn and I like to call things what they are, but as
a consequence I hit the occassional compile error for my stubborness.
Not sure if that helps you at all.
Sincerely
Mark R. Jonkman
----- Original Message -----
From: "postwick" <[email protected]>
To: [email protected]
Sent: Tuesday, July 14, 2009 9:26:38 AM GMT -05:00 US/Canada Eastern
Subject: [flexcoders] Re: create class on the fly
If I compile the class as a module, can I then load it in without having to
statically reference it in my compiled code? I can predict the package name
based on data from my database ie com.something.somethingelse etc. Then I could
compile new classes as needed and load them.
--- In [email protected], Alan Shaw <noden...@...> wrote:
>
> There are a number of important techniques for manipulating classes (as
> detailed
> in my post http://nodename.com/blog/2008/06/15/upon-reflection/ ), but
> unfortunately
> creating a class at runtime is not possible in AS3.
>
> On Mon, Jul 13, 2009 at 8:23 PM, postwick<p...@...> wrote:
> >
> >
> > I want to store descriptions of classes in an external file (such as XML)
> > or
> > database, and use them in my Flex application such that I can add, remove,
> > or change the classes in the external file with recompling the Flex
> > application.
> >
> > Is there any way to do this? In a nutshell, is there a way to create a
> > class
> > through an Actionscript function, with a for loop where the information
> > that
> > is looped over contains the definitions of the classes loaded from an
> > external source?
> >
> >
>
------------------------------------
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Alternative FAQ location:
https://share.acrobat.com/adc/document.do?docid=942dbdc8-e469-446f-b4cf-1e62079f6847
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo!
Groups Links