Monday, 15 July 2013

actionscript 3 - AS3 - target variable using another variable string value -



actionscript 3 - AS3 - target variable using another variable string value -

okay. have function , i've passed parameter through called objectname. no have no thought how or explain it. here goes.

public function moveobject(objectname):void{ //objectname holds "myname" object //i variable called mynameposition equal 10 //so need grab value of objectname myname:object. //turn string of kind - myname:string //add "position" end of mynameposition // create equal 10 trace(mynameposition); }

the functions parameters passed through alter cant utilize "myname". rather "objectname".

thanks

example:

package { import flash.display.movieclip; public class astest extends movieclip { public function astest() { init(); } private var mynameposition:int; private function init():void { moveobject({myname:{}}) } public function moveobject(objectname:object):void { var propname:string; for(propname in objectname) break; trace(propname); propname+="position"; trace(propname); this[propname] = 10; var propvalue:* = this[propname]; trace(propvalue); } } }

output:

myname mynameposition 10

is need?

string actionscript-3 variables target

No comments:

Post a Comment