RR_QQ
05-16-2008, 12:24 AM
I HAD POSTED THIS IN AS3 FORUM BY ACCIDENT BUT MOVED IT HERE
If anyone has been paying attention I have been trying to construct a custom DataGrid and for the most part I have succeeded in making my code truly reusable UNTIL the point that I needed to dynamically generate class instances. I find out that my dynamic classes cannot be instantiated UNLESS I create an instance of that class type somewhere in my code, ex:
private var forceCompilation:Array = new Array(OrderEdit);
So there is one line that is not dynamic whatsoever. But if I want to do the above I must do this:
// import place where OrderEdit is
import templates.Orders.*;
Now that's TWO lines that throw my reusable code out the door. So my question is this: is it IMPOSSIBLE to create a plugin that has no single line hard coded and truly dynamic?
So in other words is there a way that through strings I pass to my application I can construct an import statement like:
//pseudocode:
// importVar = "templates.Orders.*";
import magically_translate_to_class_path(importVar);
And through strings I can construct an array with elements such as:
//pseudocode:
// dynamicClassArray = Array(0=>"OrderEdit");
private var forceCompilation:Array = new Array();
for (i=0; i<dynamicClassArray.length; i++) {
forceCompilation.push(magically_translate_to_class _reference(dynamicClassArray[i]));
}
And then finally, I need to be able to pass variables to and from my dynamically generated class that I open up in a PopUP HOWEVER I tried translating this:
var pop1:ArrayEntryForm = ArrayEntryForm(PopUpManager.createPopUp(this, ArrayEntryForm, true));
// Set TitleWindow properties.
pop1.title = "Select File Type";
pop1.showCloseButton = true;
// Set properties of the ArrayEntryForm custom component.
pop1.targetComponent = ti1;
pop1.myArray = doctypes;
PopUpManager.centerPopUp(pop1);
This is the code I found to open up a class dynamically (which turns out is not exactly dynamic for the reasons stated above) - reed the comments in caps to see what I did/tried:
var myClassName:String = "templates." + event.templateName;
try {
var ClassReference:Class = getDefinitionByName(myClassName) as Class;
//var sdf:OrderEdit2;
// THIS WORKS
var myInstanceObject:* = new ClassReference();
// THIS LINE I USED TO REPLICATE THE EXAMPLE TO BE ABLE TO PASS VARIABLES TO MY POP UP WITHOUT SUCCESS
// HAVE NO IDEA WHAT ELSE TO TRY - error #1067 Implicit coercion value type Class to unrelated type
// mx.core:IFlexDisplayObject
//var myInstanceObject:* = ClassReference(PopUpManager.addPopUp(ClassReferenc e, this, true));
} catch( e:Error ) {
Alert.show("Could not instantiate the class " + myClassName + ". Please ensure that the class name is a valid name and that the Actionscript 3 class or MXML file exists within the project parameters.");
return;
}
Can anyone please provide some insight??? I'm at a total loss here and I refuse to believe that I just CANNOT create a truly dynamic application - that it MUST contain hardcoded sections....
Thank you!
If anyone has been paying attention I have been trying to construct a custom DataGrid and for the most part I have succeeded in making my code truly reusable UNTIL the point that I needed to dynamically generate class instances. I find out that my dynamic classes cannot be instantiated UNLESS I create an instance of that class type somewhere in my code, ex:
private var forceCompilation:Array = new Array(OrderEdit);
So there is one line that is not dynamic whatsoever. But if I want to do the above I must do this:
// import place where OrderEdit is
import templates.Orders.*;
Now that's TWO lines that throw my reusable code out the door. So my question is this: is it IMPOSSIBLE to create a plugin that has no single line hard coded and truly dynamic?
So in other words is there a way that through strings I pass to my application I can construct an import statement like:
//pseudocode:
// importVar = "templates.Orders.*";
import magically_translate_to_class_path(importVar);
And through strings I can construct an array with elements such as:
//pseudocode:
// dynamicClassArray = Array(0=>"OrderEdit");
private var forceCompilation:Array = new Array();
for (i=0; i<dynamicClassArray.length; i++) {
forceCompilation.push(magically_translate_to_class _reference(dynamicClassArray[i]));
}
And then finally, I need to be able to pass variables to and from my dynamically generated class that I open up in a PopUP HOWEVER I tried translating this:
var pop1:ArrayEntryForm = ArrayEntryForm(PopUpManager.createPopUp(this, ArrayEntryForm, true));
// Set TitleWindow properties.
pop1.title = "Select File Type";
pop1.showCloseButton = true;
// Set properties of the ArrayEntryForm custom component.
pop1.targetComponent = ti1;
pop1.myArray = doctypes;
PopUpManager.centerPopUp(pop1);
This is the code I found to open up a class dynamically (which turns out is not exactly dynamic for the reasons stated above) - reed the comments in caps to see what I did/tried:
var myClassName:String = "templates." + event.templateName;
try {
var ClassReference:Class = getDefinitionByName(myClassName) as Class;
//var sdf:OrderEdit2;
// THIS WORKS
var myInstanceObject:* = new ClassReference();
// THIS LINE I USED TO REPLICATE THE EXAMPLE TO BE ABLE TO PASS VARIABLES TO MY POP UP WITHOUT SUCCESS
// HAVE NO IDEA WHAT ELSE TO TRY - error #1067 Implicit coercion value type Class to unrelated type
// mx.core:IFlexDisplayObject
//var myInstanceObject:* = ClassReference(PopUpManager.addPopUp(ClassReferenc e, this, true));
} catch( e:Error ) {
Alert.show("Could not instantiate the class " + myClassName + ". Please ensure that the class name is a valid name and that the Actionscript 3 class or MXML file exists within the project parameters.");
return;
}
Can anyone please provide some insight??? I'm at a total loss here and I refuse to believe that I just CANNOT create a truly dynamic application - that it MUST contain hardcoded sections....
Thank you!