PDA

View Full Version : naming multiple functions


Blade27
11-16-2009, 09:03 AM
Hi,

I'm just trying to name my 12 functions using a for loop, but its not working.
It works for the event target linked to the listener, but not for the function.

Code below


for(var m:int = 0; m<12; m++){


this["holder_thumb_" +m].addEventListener(MouseEvent.CLICK, "changeImage"+m);

}


Thanks for any help

tean28
11-16-2009, 09:38 AM
what kind of code it that? :)

i dont undestand why people still use dynamic properties..

and why do you need 12 functions?
you planning on having one function for each image?
why dont you use one function for all images and a target property?

raghu_thejus
11-16-2009, 09:59 AM
u can do that task like:


for (var m:int = 0; m<12; m++) {
this["holder_thumb_" + m].addEventListener(MouseEvent.CLICK,this["changeImage"+m]);
}


what tean28 told is right.why r u writing 12 functions?u can write one only.in that u wil get wch object is clicked using


ev.target.name.split("_")[2]