Flash As3 AddMouseEvent Class


/ Published in: ActionScript 3
Save to your folder(s)

simple as3 class that help you to avoid repeat add MouseEvent each time


Copy this code and paste it in your HTML
  1. /* to USE IT
  2. import com.addMouseEvent;
  3. addMouseEvent(myBtn,startGame,false);
  4. function startGame(me:MouseEvent){
  5. switch(me.type){
  6. case "mouseOver":
  7. trace("over");
  8. break;
  9. case "mouseOut":
  10. trace("out");
  11. break;
  12. case "mouseDown";
  13. trace("down");
  14. break;
  15. }
  16. }
  17. */
  18. package com{
  19. import flash.events.MouseEvent;
  20.  
  21. public function addMouseEvent(_targ,_func,_fader:Boolean=false):void {
  22. _targ.buttonMode = true;
  23. _targ.mouseChildren = false;
  24. _targ.addEventListener(MouseEvent.MOUSE_DOWN, _func);
  25. var overFunc = _func;
  26. if (_fader) {
  27. overFunc = fader;
  28. }
  29. _targ.addEventListener(MouseEvent.MOUSE_OVER, overFunc);
  30. _targ.addEventListener(MouseEvent.MOUSE_OUT, overFunc);
  31. function fader(me:MouseEvent) {
  32. switch (me.type) {
  33. case "mouseOver" :
  34. me.currentTarget.alpha = 0.8;
  35. break;
  36. case "mouseOut" :
  37. me.currentTarget.alpha = 1;
  38. break;
  39. }
  40. }
  41. }
  42.  
  43. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.