/ Published in: ActionScript 3
URL: markaltman.ca
Code to make Sprite or MovieClip act as a button. Useful options include buttonMode to create "hand" on mouseover and mouseChildren=false so you can target the button correctly (for example, when using event.target) and not any nested children by mistake.
Expand |
Embed | Plain Text
// assume myButton is an existing sprite that you want to work like a button myButton.addEventListener(MouseEvent.MOUSE_OVER,buttonOver); myButton.addEventListener(MouseEvent.MOUSE_OUT,buttonOut); myButton.addEventListener(MouseEvent.CLICK,buttonClick); myButton.buttonMode=true; myButton.mouseChildren = false; function buttonOver(event:MouseEvent) { event.target.scaleX=1.2; // make button a bit larger event.target.scaleY=event.target.scaleX; } function buttonOut(event:MouseEvent) { event.target.scaleX=1; event.target.scaleY=event.target.scaleX; } function buttonClick(event:MouseEvent) { // click action here }
You need to login to post a comment.
