String to object

By The Little Guy | Jul 2, 2009

actionscript3

Hello, I am using a PHP server that I made using sockets sending data from one swf to another, to make a game. The following method, gets the data when it has been sent back to the swf file. So what I am doing in the function is as follows:
- get the data that was sent to the server and change it to an array
- the array looks like this array("_2", "X")
- the first value of the array is the button the person clicked
- the second value of the array is the players playing piece "X" or "O" (the game is "tic-tac-toe" by the way)

That is what is held in the dta variable.

ActionScript Code:
public function newXML(e:DataEvent){     var getData = e.data;     var pos = getData.search(“_”);     getData = getData.substring(pos);     dta = getData.split(/:/);     var obj;     if(dta[1] == “X”){         obj = new X()         playBoard.dta[0].addChild(obj);     }else{         obj = new O();         playBoard.dta[0].addChild(obj);     } }

So, the problem that I am having is I am getting this message:
TypeError: Error #1010: A term is undefined and has no properties.
at MethodInfo-6()

I know that the problem is with these two lines:
playBoard.dta[0].addChild(obj);

I believe that it has no idea what playBoard."_2".addChild(obj); means

So… Is there anyway to use a string to relate to an existing object, and place a new object inside of it?

Please, please, please let me know if you need more information or don’t understand something.

Thanks for the help!

actionscript3

Please reply at our Forum

Leave a Comment

If you would like to make a comment, please fill out the form below.

Name (required)

Email (required)

Website

Comments

© 2007 ActionScript 3.0