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
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"; layout="absolute" 
applicationComplete="init();">
<mx:Script>
        <![CDATA[
                import mx.controls.Alert;
                private var dClass1:DClass;
                private var dClass2:DClass;
                private function init():void
                {
                        var sFunctionDef:String;
                        dClass1 = new DClass();
                        dClass2 = new DClass();
                        dClass1.var1 = "one";
                        dClass1.oneFunction = function ():void
                        {
                                trace("Name:" + dClass1.Name + " id:" + 
dClass1.id + " var1:" + dClass1.var1);
                                textId.text += "\nFrom within function 
oneFunction - Name:" + dClass1.Name + " id:" + dClass1.id + " var1:" + 
dClass1.var1;
                        };
                        dClass1.stringFunction = function ():void {};
                        //sFunctionDef = "function():void {trace(\"\nCompletely 
in a string function:\" + this.Name);}";
                        //dClass1.stringFunction = sFunctionDef;
                        dClass2.var2 = 2;
                        dClass2.twoFunction = function ():void
                        {
                                trace("Name:" + dClass2.Name + " id:" + 
dClass2.id + " var2:" + dClass2.var2);
                                textId.text += "\nFrom within function 
twoFunction - Name:" + dClass2.Name + " id:" + dClass2.id + " var2:" + 
dClass2.var2;
                        };
                        dClass2.stringFunction2 = sFunctionDef;
                        button1.addEventListener(MouseEvent.CLICK, 
clickHandler);
                        button2.addEventListener(MouseEvent.CLICK, 
clickHandler);
                }
                private function clickHandler(e:MouseEvent):void
                {
                        //Alert.show("Event:" + e.type + " with target:" + 
e.target);
                        if(e.target.label == "Button1")
                        {
                                dClass1.oneFunction();
                                //dClass1.twoFunction(); //causes error
                                dClass1.stringFunction();
                        }
                        else
                        {
                                //dClass2.oneFunction(); //Causes error
                                dClass2.twoFunction();
                                //dClass2.stringFunction2();
                        }
                }
        ]]>
        </mx:Script>
        <mx:TextArea x="29" y="34" width="656" height="235" id="textId"/>
        <mx:Button id="button1" x="29" y="290" label="Button1"/>
        <mx:Button id="button2" x="141" y="290" label="Button2"/>
</mx:Application>

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);
                }
        }
}


Reply via email to