actionscript 3 - Adding movie clips with for loop action script 3 -
hey wondering if can me, trying add load of move clips , make them clickable stage in action script 3,i can work out spacing of them later keep getting errors while trying add them using :
for(var x:int = 1; x <= 10; x++) { var this["cardprint"+x] :movieclip = new this["card_"+x](); this.addchild(this["cardprint"+x]); this["cardprint"+x].addeventlistener(mouseevent.click, this["click_"+x]); }
a point in right direction alot thank you
this
scope indicator indicates current class. this["cardprint"+x]
trying find variable name, can't declare variable reference.
the way want this:
public dynamic class foobar { public function foobar() { for(var x:int = 1; x <= 10; x++) { this["cardprint"+x] = new this["card_"+x](); this.addchild(this["cardprint"+x]); this["cardprint"+x].addeventlistener(mouseevent.click, this["click_"+x]); } } }
the key making class dynamic
. allows create variable names @ run time , create them in string form using scope["varname"]
syntax. if doing on timeline in flash pro, feeling are, not possible way want it. better off creating objects in loop , storing them in array access them way instead of using syntax described above.
the datatype of each object created same whatever instantiated, won't able set movieclip
or similar.
"card_"+x
needs instantiable object (a class
). if not, cannot instantiate , error out.
i want caution poor way of putting together. room error incredibly large , using syntax difficult , difficult read in code.
Comments
Post a Comment