Code less Do More..

6 views
Skip to first unread message

flashmad

unread,
Dec 13, 2009, 11:05:10 AM12/13/09
to ActionScript User Interface Development
Here is a small trick to avoid writing multiple click events for your
buttons in as 3.0 flash projects.

You will need to follow the naming of buttons as follows [b_1 , b_2 or
btn_1, btn_2,... etc]. Now watch the code i use (assume i have 9
buttons]
for(var i=1;i<10;i++){
this["b_"+i].addEventListener(MouseEvent.CLICK,clicked);
}
function clicked(e:Event){
trace(e.target.name.split(”_”)[1]);
}
This will trace the end number of buttons [1,2,3...etc]. That means
you can differentiate each click. Using gotoAndStop(e.target.name.split
(”_”)[1]) or what ever you like will do the trick.

Skitsanos

unread,
Dec 13, 2009, 11:21:23 AM12/13/09
to ActionScript User Interface Development
yes, in this case e.target will represent the 'source' of the event,
in your case it will be this button. i would suggest to use
e.currentTarget instead.

Tinku Tharasing

unread,
Dec 13, 2009, 11:39:27 AM12/13/09
to as...@googlegroups.com
is it to avoid mouseChildren coming up as target??


--

You received this message because you are subscribed to the Google Groups "ActionScript User Interface Development" group.
To post to this group, send email to as...@googlegroups.com.
To unsubscribe from this group, send email to asui+uns...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/asui?hl=en.





--
Regards by
Tinku Tharasing
http://www.flashmadblog.com

Reply all
Reply to author
Forward
0 new messages