Revision: 14773
Updated Code
at October 11, 2009 13:06 by stiobhart
Updated Code
// add event listeners to listen for button events [mouse over, mouse out, mouse up] // and then - when one happens - trigger the function called 'buttonstuff' this.stupidbutton.addEventListener(MouseEvent.MOUSE_OVER, buttonstuff); this.stupidbutton.addEventListener(MouseEvent.MOUSE_OUT, buttonstuff); this.stupidbutton.addEventListener(MouseEvent.MOUSE_UP, buttonstuff); // end event listeners // buttonstuff function - triggered by the above listeners function buttonstuff(event:MouseEvent):void { // switch to 'switch' what the function does, depending //on which mouse event the button listener has picked up. //think of it as standing for "in case of this - do this" switch(event.type) { // in 'case' the listener detected a mouse over case MouseEvent.MOUSE_OVER: // replace the trace with your own button actions trace("button rolled over"); // each case always ends with a 'break' break; // end in 'case' the listener detected a mouse over // in 'case' the listener detected a mouse out case MouseEvent.MOUSE_OUT: // replace the trace with your own button actions trace("button rolled off"); // each case always ends with a 'break' break; // end in 'case' the listener detected a mouse out // in 'case' the listener detected a mouse up case MouseEvent.MOUSE_UP: // replace the trace with your own button actions trace("button released"); // each case always ends with a 'break' break; // end in 'case' the listener detected a mouse up } // end switch to 'switch' what the function does, depending on //which mouse event the button listener has picked up } // end buttonstuff function
Revision: 14772
Updated Code
at June 11, 2009 06:51 by stiobhart
Updated Code
// add event listeners to listen for button events [mouse over, mouse out, mouse up] // and then - when one happens - trigger the function called 'buttonstuff' this.stupidbutton.addEventListener(MouseEvent.MOUSE_OVER, buttonstuff); this.stupidbutton.addEventListener(MouseEvent.MOUSE_OUT, buttonstuff); this.stupidbutton.addEventListener(MouseEvent.MOUSE_UP, buttonstuff); // end event listeners // buttonstuff function - triggered by the above listeners function buttonstuff(event:MouseEvent):void { // switch to 'switch' what the function does, depending //on which mouse event the button listener has picked up. //think of it as standing for "in case of this - do this" switch(event.type) { // in 'case' the listener detected a mouse over case MouseEvent.MOUSE_OVER: // replace the trace with your own button actions trace("button rolled over"); // each case always ends with a 'break' break; // end in 'case' the listener detected a mouse over // in 'case' the listener detected a mouse over case MouseEvent.MOUSE_OUT: // replace the trace with your own button actions trace("button rolled off"); // each case always ends with a 'break' break; // end in 'case' the listener detected a mouse over // in 'case' the listener detected a mouse up case MouseEvent.MOUSE_UP: // replace the trace with your own button actions trace("button released"); // each case always ends with a 'break' break; // end in 'case' the listener detected a mouse up } // end switch to 'switch' what the function does, depending on //which mouse event the button listener has picked up } // end buttonstuff function
Revision: 14771
Updated Code
at June 11, 2009 06:50 by stiobhart
Updated Code
// add event listeners to listen for button events [mouse over, mouse out, mouse up] and then - when one happens - trigger the function called 'buttonstuff' this.stupidbutton.addEventListener(MouseEvent.MOUSE_OVER, buttonstuff); this.stupidbutton.addEventListener(MouseEvent.MOUSE_OUT, buttonstuff); this.stupidbutton.addEventListener(MouseEvent.MOUSE_UP, buttonstuff); // end event listeners // buttonstuff function - triggered by the above listeners function buttonstuff(event:MouseEvent):void { // switch to 'switch' what the function does, depending //on which mouse event the button listener has picked up. //think of it as standing for "in case of this - do this" switch(event.type) { // in 'case' the listener detected a mouse over case MouseEvent.MOUSE_OVER: // replace the trace with your own button actions trace("button rolled over"); // each case always ends with a 'break' break; // end in 'case' the listener detected a mouse over // in 'case' the listener detected a mouse over case MouseEvent.MOUSE_OUT: // replace the trace with your own button actions trace("button rolled off"); // each case always ends with a 'break' break; // end in 'case' the listener detected a mouse over // in 'case' the listener detected a mouse up case MouseEvent.MOUSE_UP: // replace the trace with your own button actions trace("button released"); // each case always ends with a 'break' break; // end in 'case' the listener detected a mouse up } // end switch to 'switch' what the function does, depending on //which mouse event the button listener has picked up } // end buttonstuff function
Revision: 14770
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at June 11, 2009 06:44 by stiobhart
Initial Code
// add event listeners to listen for button events [mouse over, mouse out, mouse up] and then - when one happens - trigger the function called 'buttonstuff' this.stupidbutton.addEventListener(MouseEvent.MOUSE_OVER, buttonstuff); this.stupidbutton.addEventListener(MouseEvent.MOUSE_OUT, buttonstuff); this.stupidbutton.addEventListener(MouseEvent.MOUSE_UP, buttonstuff); // end event listeners // buttonstuff function - triggered by the above listeners function buttonstuff(event:MouseEvent):void { // switch to 'switch' what the function does, depending on which mouse event the button listener has picked up. think of it as standing for "in case of this - do this" switch(event.type) { // in 'case' the listener detected a mouse over case MouseEvent.MOUSE_OVER: // replace the trace with your own button actions trace("button rolled over"); // each case always ends with a 'break' break; // end in 'case' the listener detected a mouse over // in 'case' the listener detected a mouse over case MouseEvent.MOUSE_OUT: // replace the trace with your own button actions trace("button rolled off"); // each case always ends with a 'break' break; // end in 'case' the listener detected a mouse over // in 'case' the listener detected a mouse up case MouseEvent.MOUSE_UP: // replace the trace with your own button actions trace("button released"); // each case always ends with a 'break' break; // end in 'case' the listener detected a mouse up } // end switch to 'switch' what the function does, depending on which mouse event the button listener has picked up } // end buttonstuff function
Initial URL
Initial Description
actionscript3 version of a more complex button action, which responds to rollover, rollout and clicking. this method uses one single 'buttonstuff' function with a 'switch' inside which causes the function to respond differently, depending on what the user action on the button was. i think this is a neater way to do it than to have each individual 'addEventListener' trigger a separate function. in actionscript3, button actions can no longer be attached to the buttons themselves or called from the main timeline. you need to put an 'addEventListener' in the timeline to 'listen' for interaction with the button and then call an appropriate function to deal with that action. the button needs to have an instance name. in this case it is called 'stupidbutton'
Initial Title
actionscript 3 - button action [listen for multiple events. eg. MOUSE_OVER, MOUSE_OUT, MOUSE_UP]
Initial Tags
actionscript, flash, button
Initial Language
ActionScript 3