0

so.... eval() out of the question, any idea to do this? I also don't know how to use "this" expression or set() in actionscript 3 ( i seem couldn't find any complete reference on it ), just say through php file a multiple variable (test1, test2, test3,...) sent by "echo", how the flash aplication recieved it? I'm trying not to use xml on mysql to php to flash aplication. Simply how to change a string to a variable ?

example

(in as3-actions frame panel)

function datagridfill(event:MouseEvent):void{
   var varfill:URLVariables = new URLVariables();
   varfill.tell = "do it";
   var filler:URLRequest = new URLRequest();
   filler.url = "http://127.0.0.1/flashdbas3/sendin.php";
   filler.data = varfill;
   var filling:URLLoader = new URLLoader();
   filling.dataFormat = URLLoaderDataFormat.VARIABLES;
   filling.load(filler);
   filling.addEventListener(Event.COMPLETE, datain);

   function datain(evt:Event){
      var arraygrid:Array = new Array();
      testing.text = evt.target.Name2 // worked
      // just say i = 1
      i=1;
      arraygrid.push({Name:this["evt.target.Name"+i],
                      Test:this.["evt.target.Test"+i]}); // error
      //or
      arraygrid.push({Name:this["Name"+i],
                      Test:this.["Test"+i]}); // error too
      // eval() noexistent, set() didn't worked on actions frame panel
      //?????
   }   
};

I hope it's very clear.

1
  • I posted an answer, but your question isn't clearly phrased. Revise it for clarity, and add a more detailed description of what you're trying to do, and you'll get better results. Commented Jun 20, 2009 at 17:34

2 Answers 2

3

You could use this[varName] if I understand your question right.

So if varName is a variable containing a string which should be a variables name, you could set and read that variable like this:

this[varName] = "someValue";
trace(this[varName]);

Update:

In your example, you could try: evt.target["Test"+i] instead of Test:this.["evt.target.Test"+i]

Sign up to request clarification or add additional context in comments.

Comments

0

If you have a set of strings that you'd like to associate with values, the standard AS3 approach is to use an object as a hash table:

var o = {}
o["test1"] = 7
o["test2"] = "fish"
print(o["test1"])

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.