Hi 

Somewhere you will need to write an .as file and compile it into a swf in order 
to use it at runtime. Flash can't compile an .as file or a string at runtime. 

You can however, compile any number of .as files into a Flex Library project, 
load that library at runtime then using getDefinitionByName retrieve the class 
reference then instantiate it. 

One way I do this in a semi automated way is as follows: 

Create a series of Flex Library projects in Flex Builder or Flash Builder. 
Create the appropriate classes in each of the library projects. 
Create one Flex project and name it something like Library_Builder. 
Link all the Flex Library projects against it as RSLs 
Set each RSL to auto-extract and give it a directory and filename to 
autoextract into. 
Then I compile that one project to recompile all my libraries and when I need 
the runtime (vs. debug versions) I just do a release build. 

I never post the Library_Builder project to my site, it has no code in it, it 
simply serves to build the debug and release versions of my libraries en-masse 
without having to do a lot of jumping through hoops. I actually configure the 
Library_Builder to build itself into the debug folder of my real project and 
the release into the release folder of my real project. I just skip posting it 
and even if it gets posted by accident, its totally useless. One could link a 
folder in Flex Builder from one project to another, but I like to check my 
folders into SVN and it gets checked out to the server so its easier to do it 
into my main project. 

You can have as many library projects as you want to break things into 
"modular" libraries to load on demand at runtime into your main project. To 
have a lot of one class library projects would be rather a nightmare to deal 
with, but grouping classes that are used together into the same library project 
is often wiser and less prone to dependency errors. Dependeny errors result if 
your library project needs access to classes in another library and that 
library is linked to as an external library during compile. Then you need to 
make sure the dependencies are resolved by having all necesary libraries 
loaded. I tend to use only a handful of very distinct libraries like this where 
all the dependencies are pretty much resolved internally or can be resolved by 
loading a single common library upfront first. 

I don't have access to the full thread right now so I'm not sure exactly what 
you are doing. But in order to access a class you need a compiled version of 
the class - aka in a swf somewhere. And you need to know the name of the class 
(fully qualified). You need to load the swf at runtime then access the class. 

Sincerely 
Mark R. Jonkman 




----- Original Message ----- 
From: "postwick" <[email protected]> 
To: [email protected] 
Sent: Tuesday, July 14, 2009 9:32:02 AM GMT -05:00 US/Canada Eastern 
Subject: [flexcoders] Re: create class on the fly 

>From your blog post... 

var myClass:Class = getDefinitionByName("com.myDomain.myPackage.SomeClass"); 


Does this mean I don't have to create the class as a .as file and compile it 
into the SWF, I can just reference it this way? Then I could add a new class to 
myPackage and tell my app (via db, XML, etc) that there is a new class there to 
load? 

The point to all of this is a dynamic application where an end user can add 
their own tables, and I need classes for those objects so that I can pass them 
back and forth with data messaging. 


--- 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 



Reply via email to