In Actionscript 3.0 you must use addEventListener() to intercept any event:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | / ** * Given a MovieClip mc, you set events and handlers * / ( MouseEvent . CLICK , on_click ) ; mc. addEventListener ( MouseEvent . CLICK, on_click); ( MouseEvent . ROLL_OVER , on_roll_over ) ; mc. addEventListener ( MouseEvent . ROLL_OVER, on_roll_over); ( MouseEvent . ROLL_OUT , on_roll_out ) ; mc. addEventListener ( MouseEvent . ROLL_OUT, on_roll_out); / ** * Functions hander for the above events * / e : MouseEvent ) : void { on_click function (e: MouseEvent ): void { / / Click } e : MouseEvent ) : void { on_roll_over function (e: MouseEvent ): void { / / Roll over } e : MouseEvent ) : void { on_roll_out function (e: MouseEvent ): void { / / Roll-out } |
Alternatively you can use the form:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | ( MouseEvent . CLICK , on_handler ) ; mc. addEventListener ( MouseEvent . CLICK, on_handler); ( MouseEvent . ROLL_OVER , on_handler ) ; mc. addEventListener ( MouseEvent . ROLL_OVER, on_handler); ( MouseEvent . ROLL_OUT , on_handler ) ; mc. addEventListener ( MouseEvent . ROLL_OUT, on_handler); / ** * I create a single function to handle all events * / e : MouseEvent ) : void { on_handler function (e: MouseEvent ): void { e . type ) { switch (and. type) { . CLICK : houses MouseEvent . CLICK: / / Click break; . ROLL_OVER : houses MouseEvent . ROLL_OVER: / / Roll over break; . ROLL_OUT : houses MouseEvent . ROLL_OUT: / / Roll-out break; } } |










[...] Very short trick: addEventListener () AS3, a handler more events in Actionscript 3.0 you must use the addEventListener () to intercept any [...]
Hello, I like how you've improved, but I ask you something, if I had more than one MovieClip mc, type: mc1, mc2 ... .. (could be for example the buttons on a menu), how to manage them? Thanks
@ Robert:
, in questo caso
MouseEvent. In the functionon_handleryou can refer to the object of typeEvent, in this caseMouseEvent. This object, in fact, allows you to have information about the object that received the event. If you try this:2
3
4
e . target . name ) ; trace (and. target. name);
/ / ...
}
) ti permetterà di sapere quale MovieClip hai selezionato. The property
target(orcurrentTarget) will let you know that you have selected MovieClip.che, anche se a prima vista sembrano del tutto identici, in alcuni casi (vedi bottoni complessi costruiti con più MovieClip annidati) possono darti la corretta informazione che cerchi. See the documentation is in the detail of
targetthatcurrentTargetthat although at first sight appear to be quite identical, in some cases (see buttons built with more complex nested MovieClips) can give you the correct information you are looking for.@ Giovambattista Fazioli: I'll go look ...:) ... nice ... if I resubmit ..:)
@ Giovambattista Fazioli:
2
3
4
5
6
7
8
9
10
11
12
13
14
( MouseEvent . MOUSE_OUT , on_handler ) ; btn1_mc. addEventListener ( MouseEvent . MOUSE_OUT, on_handler);
e : MouseEvent ) { on_handler function (e: MouseEvent ) {
e . type ) { switch (and. type) {
. MOUSE_OVER : houses MouseEvent . MOUSE_OVER:
e . currentTarget . name ) ; //funziona, visualizza "btn1_mc" ossia il nome dell'istanza del primo pulsante trace (and. currentTarget. name) / / works, it displays "btn1_mc" or the name of the first button
( 2 ) ; btn1_mc. gotoAndPlay (2);
break;
. MOUSE_OUT : houses MouseEvent . MOUSE_OUT:
( 16 ) ; btn1_mc. gotoAndPlay (16);
break;
}
}
Then
works, but how can I attach to education next sequence? in place of
@ Robert: It is very simple:
e.targetis a pointer to the instance of the MovieClip, then just use:In practice
btn1_mc, or any other instance, corresponds toe.target@ Giovambattista Fazioli: Well what to say, I tried to be good with geek
[Cc_actionscript3] (e.currentTarget.name). GotoAndPlay (2) [\ as] ... taken away ... And so name the parentheses, and function ... so ... .. THANK YOU ....:)
@ Robert: I would conclude, if someone tried to info about that in the case with more cubic meters (eg buttons), with an array and a click you can group and assign different mc "addEventListener" es :
2
3
4
5
. addEventListener ( MouseEvent . CLICK , on_handler ) ; btn_array [i]. addEventListener ( MouseEvent . CLICK, on_handler);
. addEventListener ( MouseEvent . MOUSE_OVER , on_handler ) ; btn_array [i]. addEventListener ( MouseEvent . MOUSE_OVER, on_handler);
. addEventListener ( MouseEvent . MOUSE_OUT , on_handler ) ; btn_array [i]. addEventListener ( MouseEvent . MOUSE_OUT, on_handler);
}
... .. Hello and I hope to be useful to someone else ....:)
@ Roberto: excellent! Also finally, if the series of "buttons" (MovieClip) are placed in a container MovieClip, you can even avoid the array and loop over all the "children" of the container. In this regard I suggest you read Everything you ever wanted to do with Actionscript 3
Greetings and thanks for your contributions