[flexcoders] Re: create class on the fly

2009-07-15 Thread postwick
Thanks for pointing me in the right direction.  I had no idea how well passing 
Flex Objects and CF Structures back-and-forth works.  It's so simple, and CF 
Structures are fast.  At the moment it displays object [Object] in the grid :-) 
but I'm able to bind a form to the properties of the object in that grid 
column, which is pretty cool.

I'm a couple small steps away from having the complete solution I have been 
looking for: using LCDS with multiple tables but only ONE generic class.

Here's a bonus question.  Within a data service can you have "subtopics" like 
you can have for messaging services?  If so, then I'd be able to get away with 
having only one destination.  Otherwise, I'll need a destination for every 
table, but that's not such a big deal.

--- In flexcoders@yahoogroups.com, "jer_ela"  wrote:
>
> Just have your cfc return the results as a query, or as an array of structs.  
> The first will be converted into an ArrayCollection of generic objects in 
> Flex, and the second into an Array of objects.  Each of these objects will 
> have a property for each column in the record.  
> 
> Flex will be quite happy with these object and will let you do pretty much 
> anything you want to do with them.
> 
> You can use 
> 
> for (var key:String in recordObject) 
> 
> to get the property names.  Since your queries are going to be dynamic you 
> are going to have to process them dynamically and this is how you do it.
> 
> You could also have your cfc return metadata about the result set, to tell 
> you which properties are the primary keys, and anything else you need to know 
> about the result to process it correctly.
> 
> Having the server return objects that automatically get converted to typed 
> flex objects is great when you know what type of objects are going to be 
> returned.  But if you don't Flex can handle untyped dynamic objects just 
> fine, and you should use them when the results of a service can't be known at 
> compile time.
> 
> --- In flexcoders@yahoogroups.com, "postwick"  wrote:
> >
> > I cannot predict at compile-time what the name (or properties) of the class 
> > will be.  I need to CREATE the class at runtime, AND add the properties to 
> > it.  It seems, so far, that this is not possible.
> > 
> > However, what I'm doing sounds very similar to your project.  It's not so 
> > much the sheer number of tables (although a few dozen) but the fact that 
> > the application allows the creation of new tables (so I need a new class) 
> > and columns (so the properties might change).
> > 
> > I can easily have my app write new destinations to the config file for any 
> > new table created.  I can even write the necessary CFCs to disk based upon 
> > schema changes within the app.  But I cannot find a way to get the classes 
> > I need.
> > 
> > All tables share the same foreign key column name, which is helpful.  My 
> > idea is this...set up one class that has two properties - the foreign key 
> > and a second column.  I would have one destination for each table, but all 
> > destinations will point to the same class.  When my CFCs pull data, I will 
> > have them return the primary key along with all other data encoded (XML or 
> > something) into the second property.  Then on the client side I can manage 
> > it by filling an ArrayCollection, then having a function that parses the 
> > actual columns and rows (from the second property) into a second 
> > ArrayCollection that my datagrid is actually bound to.  Creates/updates 
> > would go in the reverse direction - placed into the second ArrayCollection 
> > and then processed up to the two-property format for the first one, at 
> > which point LCDS will take over.
> > 
> > As I think through it, this should work.  Thoughts?
> > 
> > --- In flexcoders@yahoogroups.com, "wrhinfl"  wrote:
> > >
> > > Ok, I think the way your question is worded can cause problems with the 
> > > answer you get.
> > > 
> > > If your real question was "Can a class be modified during runtime and 
> > > how?"  Would this be the same question you are asking?
> > > 
> > > I searched the ASDocs and found Dynamic Class, which allows you to add 
> > > variables and functions to an instance of a class.  I created a simple 
> > > application and uses one AS class twice, creating different variables and 
> > > functions in the two instances.
> > > 
> > > The project I am working on is trying to do something very similar where 
> > > I don't want hundreds of classes to match the hundreds of tables (and 
> > > would require hundreds of java classes on the server).  
> > > 
> > > And your question made me do some searching, so let me know if this 
> > > question and answer are closer to what you are trying to accomplish in 
> > > your project and I can share my simple code (two files with 70 lines of 
> > > code, no comments).
> > > 
> > > --- In flexcoders@yahoogroups.com, "postwick"  wrote:
> > > >
> > > > I want to store descriptions of classes in an external fil

[flexcoders] Re: create class on the fly

2009-07-15 Thread wrhinfl
Ok, I am sorry, I think there were still two bad lines of code in that example 
for trying to get a function into the class dynamically with a string variable.

But I am able to add properties to the class dynamically based on the value of 
a string variable:
var sNewProperty:String;
sNewProperty = "specialVar";
dClass1[sNewProperty] = "You can, you can see my dynamic variable!";
trace(dClass1[sNewProperty]);
trace(dClass1.specialVar); //will print the same thing as the previous line, so 
the actual property name is "specialVar" from the string variable.




[flexcoders] Re: create class on the fly

2009-07-15 Thread jer_ela
Just have your cfc return the results as a query, or as an array of structs.  
The first will be converted into an ArrayCollection of generic objects in Flex, 
and the second into an Array of objects.  Each of these objects will have a 
property for each column in the record.  

Flex will be quite happy with these object and will let you do pretty much 
anything you want to do with them.

You can use 

for (var key:String in recordObject) 

to get the property names.  Since your queries are going to be dynamic you are 
going to have to process them dynamically and this is how you do it.

You could also have your cfc return metadata about the result set, to tell you 
which properties are the primary keys, and anything else you need to know about 
the result to process it correctly.

Having the server return objects that automatically get converted to typed flex 
objects is great when you know what type of objects are going to be returned.  
But if you don't Flex can handle untyped dynamic objects just fine, and you 
should use them when the results of a service can't be known at compile time.

--- In flexcoders@yahoogroups.com, "postwick"  wrote:
>
> I cannot predict at compile-time what the name (or properties) of the class 
> will be.  I need to CREATE the class at runtime, AND add the properties to 
> it.  It seems, so far, that this is not possible.
> 
> However, what I'm doing sounds very similar to your project.  It's not so 
> much the sheer number of tables (although a few dozen) but the fact that the 
> application allows the creation of new tables (so I need a new class) and 
> columns (so the properties might change).
> 
> I can easily have my app write new destinations to the config file for any 
> new table created.  I can even write the necessary CFCs to disk based upon 
> schema changes within the app.  But I cannot find a way to get the classes I 
> need.
> 
> All tables share the same foreign key column name, which is helpful.  My idea 
> is this...set up one class that has two properties - the foreign key and a 
> second column.  I would have one destination for each table, but all 
> destinations will point to the same class.  When my CFCs pull data, I will 
> have them return the primary key along with all other data encoded (XML or 
> something) into the second property.  Then on the client side I can manage it 
> by filling an ArrayCollection, then having a function that parses the actual 
> columns and rows (from the second property) into a second ArrayCollection 
> that my datagrid is actually bound to.  Creates/updates would go in the 
> reverse direction - placed into the second ArrayCollection and then processed 
> up to the two-property format for the first one, at which point LCDS will 
> take over.
> 
> As I think through it, this should work.  Thoughts?
> 
> --- In flexcoders@yahoogroups.com, "wrhinfl"  wrote:
> >
> > Ok, I think the way your question is worded can cause problems with the 
> > answer you get.
> > 
> > If your real question was "Can a class be modified during runtime and how?" 
> >  Would this be the same question you are asking?
> > 
> > I searched the ASDocs and found Dynamic Class, which allows you to add 
> > variables and functions to an instance of a class.  I created a simple 
> > application and uses one AS class twice, creating different variables and 
> > functions in the two instances.
> > 
> > The project I am working on is trying to do something very similar where I 
> > don't want hundreds of classes to match the hundreds of tables (and would 
> > require hundreds of java classes on the server).  
> > 
> > And your question made me do some searching, so let me know if this 
> > question and answer are closer to what you are trying to accomplish in your 
> > project and I can share my simple code (two files with 70 lines of code, no 
> > comments).
> > 
> > --- In flexcoders@yahoogroups.com, "postwick"  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] Re: create class on the fly

2009-07-15 Thread wrhinfl
So you need a process that maps future (currently un)named column names into a 
class property name (which is also currently unnamed)?

I think you want to work with a dynamic class.  It will allow you to add new 
properties at run time.  It will also allow you to add new functions at run 
time (although with this one I am not able to assign the whole function into a 
string variable and then put that function into the class).

Have a quick look at the mxml and actionscript (dynamic class) I quickly 
created last night.  The actionscript class has almost nothing in it.  In the 
mxml code I create two instances of this class, add different properties to 
each instance, and add different functions to each instance.  Then on the 
button clicks I am executing the different functions that have been dynamically 
added (which print both properties defined in the class and properties that 
have been dynamically added).

You can see a few lines I have commented out since I could not get the function 
code assigned to a string variable and then added into the class as a function, 
at least not that quickly.  Ok, you would still have to figure out a way to get 
the property names to "match" your column names for things to flow smoothly 
between the database and swf file.

file:dynamic_text.mxml

http://www.adobe.com/2006/mxml"; layout="absolute" 
applicationComplete="init();">








file:DClass.as
package
{
public dynamic class DClass
{
public const Name:String = "DClass";
public var id:Date;
public function DClass()
{
id = new Date();
trace(id);
}
}
}




[flexcoders] Re: create class on the fly

2009-07-15 Thread postwick
I cannot predict at compile-time what the name (or properties) of the class 
will be.  I need to CREATE the class at runtime, AND add the properties to it.  
It seems, so far, that this is not possible.

However, what I'm doing sounds very similar to your project.  It's not so much 
the sheer number of tables (although a few dozen) but the fact that the 
application allows the creation of new tables (so I need a new class) and 
columns (so the properties might change).

I can easily have my app write new destinations to the config file for any new 
table created.  I can even write the necessary CFCs to disk based upon schema 
changes within the app.  But I cannot find a way to get the classes I need.

All tables share the same foreign key column name, which is helpful.  My idea 
is this...set up one class that has two properties - the foreign key and a 
second column.  I would have one destination for each table, but all 
destinations will point to the same class.  When my CFCs pull data, I will have 
them return the primary key along with all other data encoded (XML or 
something) into the second property.  Then on the client side I can manage it 
by filling an ArrayCollection, then having a function that parses the actual 
columns and rows (from the second property) into a second ArrayCollection that 
my datagrid is actually bound to.  Creates/updates would go in the reverse 
direction - placed into the second ArrayCollection and then processed up to the 
two-property format for the first one, at which point LCDS will take over.

As I think through it, this should work.  Thoughts?

--- In flexcoders@yahoogroups.com, "wrhinfl"  wrote:
>
> Ok, I think the way your question is worded can cause problems with the 
> answer you get.
> 
> If your real question was "Can a class be modified during runtime and how?"  
> Would this be the same question you are asking?
> 
> I searched the ASDocs and found Dynamic Class, which allows you to add 
> variables and functions to an instance of a class.  I created a simple 
> application and uses one AS class twice, creating different variables and 
> functions in the two instances.
> 
> The project I am working on is trying to do something very similar where I 
> don't want hundreds of classes to match the hundreds of tables (and would 
> require hundreds of java classes on the server).  
> 
> And your question made me do some searching, so let me know if this question 
> and answer are closer to what you are trying to accomplish in your project 
> and I can share my simple code (two files with 70 lines of code, no comments).
> 
> --- In flexcoders@yahoogroups.com, "postwick"  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] Re: create class on the fly

2009-07-14 Thread wrhinfl
Ok, I think the way your question is worded can cause problems with the answer 
you get.

If your real question was "Can a class be modified during runtime and how?"  
Would this be the same question you are asking?

I searched the ASDocs and found Dynamic Class, which allows you to add 
variables and functions to an instance of a class.  I created a simple 
application and uses one AS class twice, creating different variables and 
functions in the two instances.

The project I am working on is trying to do something very similar where I 
don't want hundreds of classes to match the hundreds of tables (and would 
require hundreds of java classes on the server).  

And your question made me do some searching, so let me know if this question 
and answer are closer to what you are trying to accomplish in your project and 
I can share my simple code (two files with 70 lines of code, no comments).

--- In flexcoders@yahoogroups.com, "postwick"  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?
>




Re: [flexcoders] Re: create class on the fly

2009-07-14 Thread Julien Nicoulaud
Interesting topic !
I would like to go further on the dynamic class manipulations:
Does anybody see a way to list all classes from a package that implement a
given Interface ?
Well, the part "that implement a given Interface" is easy to do using
isPrototypeOf(), but the "list all classes from a package" part ?

2009/7/14 ag_rcuren 

>
>
> To return a class is pretty simple. If you look at the source of the
> Modules they have create method. For my example they are returning instances
> but there is no reason you can not return a Class from these, infact I have
> done it before so I know it works.
>
> import mystuff.junk.SomeClass;
> import mystuff.junk.AnotherClass;
>
> public function create(type:String):*
> {
> switch (type)
> {
> case "SomeClass":
> return SomeClass
> case "AnotherClass":
> return AnotherClass
> break;
> default:
> break;
> }
> return null;
> }
>
> This will give you back a Class which you can then use as expected.
>
> Looking at it now I should have used a different name other than
> createdInstance for the getter in DynamicFactory because it really does not
> have to be an instance of something it can be any type.
>
>
> --- In flexcoders@yahoogroups.com ,
> "postwick"  wrote:
> >
> > Thanks for everyone's help. I think this points me in the right
> direction.
> >
> > Of course, if there's a way to successfully use data messaging without
> instantiating classes...that would eliminate my need to do this. But I don't
> think there is...
> >
> > --- In flexcoders@yahoogroups.com ,
> "ag_rcuren"  wrote:
> > >
> > > Yes you could create the class and build it into an RSL. Once the RSL
> is loaded you can just reference it by name. When you add or make changes
> you just need to rebuild the RSL or push a new RSL out and have a way for
> your app to know whats available.
> > >
> > > I found it easier to use Modules, because they are easier to build. I
> have examples of both RSL and Modules on that blog both have source enabled
> so you can take a look.
> > >
> > > I have an app that lets users pick and choose "widgets" they want and I
> load only the components they want into the app via a config file. When ever
> I want to add new components I just publish a new module and update my
> database so my apps knows about it.
> > >
> > > --- In flexcoders@yahoogroups.com ,
> "postwick"  wrote:
> > > >
> > > > 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 flexcoders@yahoogroups.com ,
> Alan Shaw  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 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] Re: create class on the fly

2009-07-14 Thread ag_rcuren
To return a class is pretty simple. If you look at the source of the Modules 
they have create method. For my example they are returning instances but there 
is no reason you can not return a Class from these, infact I have done it 
before so I know it works.

import mystuff.junk.SomeClass;
import mystuff.junk.AnotherClass;

public function create(type:String):*
{
switch (type)
{
case "SomeClass":
return SomeClass
case "AnotherClass":
return AnotherClass
break;
default:
break;
}
return null;
}

This will give you back a Class which you can then use as expected. 

Looking at it now I should have used a different name other than 
createdInstance for the getter in DynamicFactory because it really does not 
have to be an instance of something it can be any type.



--- In flexcoders@yahoogroups.com, "postwick"  wrote:
>
> Thanks for everyone's help.  I think this points me in the right direction.
> 
> Of course, if there's a way to successfully use data messaging without 
> instantiating classes...that would eliminate my need to do this.  But I don't 
> think there is...
> 
> --- In flexcoders@yahoogroups.com, "ag_rcuren"  wrote:
> >
> > Yes you could create the class and build it into an RSL. Once the RSL is 
> > loaded you can just reference it by name. When you add or make changes you 
> > just need to rebuild the RSL or push a new RSL out and have a way for your 
> > app to know whats available.
> > 
> > I found it easier to use Modules, because they are easier to build. I have 
> > examples of both RSL and Modules on that blog both have source enabled so 
> > you can take a look.
> > 
> > I have an app that lets users pick and choose "widgets" they want and I 
> > load only the components they want into the app via a config file. When 
> > ever I want to add new components I just publish a new module and update my 
> > database so my apps knows about it.
> > 
> > --- In flexcoders@yahoogroups.com, "postwick"  wrote:
> > >
> > > 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 flexcoders@yahoogroups.com, Alan Shaw  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 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?
> > > > >
> > > > >
> > > >
> > >
> >
>




Re: [flexcoders] Re: create class on the fly

2009-07-14 Thread mark . jonkman
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"  
To: flexcoders@yahoogroups.com 
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 flexcoders@yahoogroups.com, Alan Shaw  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 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 





[flexcoders] Re: create class on the fly

2009-07-14 Thread postwick
Thanks for everyone's help.  I think this points me in the right direction.

Of course, if there's a way to successfully use data messaging without 
instantiating classes...that would eliminate my need to do this.  But I don't 
think there is...

--- In flexcoders@yahoogroups.com, "ag_rcuren"  wrote:
>
> Yes you could create the class and build it into an RSL. Once the RSL is 
> loaded you can just reference it by name. When you add or make changes you 
> just need to rebuild the RSL or push a new RSL out and have a way for your 
> app to know whats available.
> 
> I found it easier to use Modules, because they are easier to build. I have 
> examples of both RSL and Modules on that blog both have source enabled so you 
> can take a look.
> 
> I have an app that lets users pick and choose "widgets" they want and I load 
> only the components they want into the app via a config file. When ever I 
> want to add new components I just publish a new module and update my database 
> so my apps knows about it.
> 
> --- In flexcoders@yahoogroups.com, "postwick"  wrote:
> >
> > 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 flexcoders@yahoogroups.com, Alan Shaw  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 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] Re: create class on the fly

2009-07-14 Thread ag_rcuren
Yes you could create the class and build it into an RSL. Once the RSL is loaded 
you can just reference it by name. When you add or make changes you just need 
to rebuild the RSL or push a new RSL out and have a way for your app to know 
whats available.

I found it easier to use Modules, because they are easier to build. I have 
examples of both RSL and Modules on that blog both have source enabled so you 
can take a look.

I have an app that lets users pick and choose "widgets" they want and I load 
only the components they want into the app via a config file. When ever I want 
to add new components I just publish a new module and update my database so my 
apps knows about it.

--- In flexcoders@yahoogroups.com, "postwick"  wrote:
>
> 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 flexcoders@yahoogroups.com, Alan Shaw  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 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?
> > >
> > >
> >
>




Re: [flexcoders] Re: create class on the fly

2009-07-14 Thread mark . jonkman
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"  
To: flexcoders@yahoogroups.com 
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 flexcoders@yahoogroups.com, Alan Shaw  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 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 





[flexcoders] Re: create class on the fly

2009-07-14 Thread postwick
Yeah, I saw your post in my hours of Googling last night.  Seems very 
promising.  The idea is to have a database table that stores a list of classes 
and their properties, and instantiate them at runtime without having to 
recompile the app - so that if a new class is added to the db my app can use it 
on the fly.

Would your method of using Modules solve this?  It appears so, but I haven't 
had a chance to try it out. In your post you say:

"This setup is very flexible because I can return both instances and classes 
from the Module."

Can you give me an example of how you would return a Class?

--- In flexcoders@yahoogroups.com, "ag_rcuren"  wrote:
>
> This might help you, its a little something I wrote a little while ago.
> 
> http://flexinonroids.wordpress.com/2009/05/27/flex-3-dynamically-loading-components-at-runtime/
> 
> 
> --- In flexcoders@yahoogroups.com, "postwick"  wrote:
> >
> > 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 flexcoders@yahoogroups.com, Alan Shaw  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 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] Re: create class on the fly

2009-07-14 Thread postwick
>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 flexcoders@yahoogroups.com, Alan Shaw  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 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] Re: create class on the fly

2009-07-14 Thread ag_rcuren
This might help you, its a little something I wrote a little while ago.

http://flexinonroids.wordpress.com/2009/05/27/flex-3-dynamically-loading-components-at-runtime/


--- In flexcoders@yahoogroups.com, "postwick"  wrote:
>
> 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 flexcoders@yahoogroups.com, Alan Shaw  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 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] Re: create class on the fly

2009-07-14 Thread postwick
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 flexcoders@yahoogroups.com, Alan Shaw  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 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?
> >
> >
>