/ Published in: ActionScript 3
simple as3 class that help you to avoid repeat add MouseEvent each time
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/* to USE IT import com.addMouseEvent; addMouseEvent(myBtn,startGame,false); function startGame(me:MouseEvent){ switch(me.type){ case "mouseOver": trace("over"); break; case "mouseOut": trace("out"); break; case "mouseDown"; trace("down"); break; } } */ package com{ import flash.events.MouseEvent; public function addMouseEvent(_targ,_func,_fader:Boolean=false):void { _targ.buttonMode = true; _targ.mouseChildren = false; _targ.addEventListener(MouseEvent.MOUSE_DOWN, _func); var overFunc = _func; if (_fader) { overFunc = fader; } _targ.addEventListener(MouseEvent.MOUSE_OVER, overFunc); _targ.addEventListener(MouseEvent.MOUSE_OUT, overFunc); function fader(me:MouseEvent) { switch (me.type) { case "mouseOver" : me.currentTarget.alpha = 0.8; break; case "mouseOut" : me.currentTarget.alpha = 1; break; } } } }