2020/10/1

多场景画板的ActionScript代码

Adobe Animate应用多场景画板的方法,第一场景画板需要的代码
  1. import flash.display.MovieClip;   
  2. import flash.events.MouseEvent;   
  3.   
  4. var sp:MovieClip=new MovieClip();   
  5. sp.graphics.lineStyle(0,0xEF856E,0.0);   
  6. sp.graphics.beginFill(0x000000,0.0);   
  7. sp.graphics.drawRect(1771,881,60,60);   
  8. sp.graphics.endFill();   
  9. sp.buttonMode=true;   
  10.   
  11. var mc:MovieClip=new MovieClip();   
  12.   
  13.   
  14. function init(event:Event):void {   
  15. mc.graphics.lineStyle(4);   
  16. stage.addEventListener(MouseEvent.MOUSE_DOWN,onMD);   
  17. stage.addEventListener(MouseEvent.MOUSE_UP,onMU);   
  18. sp.addEventListener(MouseEvent.MOUSE_DOWN,SMD);   
  19. sp.addEventListener(MouseEvent.MOUSE_UP,SMU);   
  20. function onMD(event:MouseEvent):void {   
  21. mc.graphics.moveTo(mouseX,mouseY);   
  22. stage.addEventListener(MouseEvent.MOUSE_MOVE,onMM);   
  23. }   
  24. function onMU(event:MouseEvent):void {   
  25. stage.removeEventListener(MouseEvent.MOUSE_MOVE,onMM);   
  26. }   
  27. function onMM(event:MouseEvent):void {   
  28. mc.graphics.lineTo(mouseX,mouseY);   
  29. }   
  30. function SMD(event:MouseEvent):void {   
  31. sp.startDrag(false);   
  32. mc.graphics.clear();   
  33. stage.removeEventListener(MouseEvent.MOUSE_DOWN,onMD);   
  34. }   
  35. function SMU(event:MouseEvent):void {   
  36. sp.stopDrag();   
  37. sp.x=0;   
  38. sp.y=0;   
  39. }   
  40. }  
第一场景每个按钮需要添加clearHuaBan
  1. function go_a(e:MouseEvent){   
  2.     clearHuaBan();   
  3.     gotoAndPlay(1,“go_a”);   
  4. }   
  5. function go_b(e:MouseEvent){   
  6.     clearHuaBan();   
  7.     gotoAndPlay(1,“go_b”);   
  8. }   
  9. function clearHuaBan(){   
  10.     if(sp && stage.contains(sp) && stage.contains(mc) ){   
  11.         removeChild(sp);   
  12.         removeChild(mc);   
  13.         stage.removeEventListener(Event.ENTER_FRAME,init);   
  14.     }   
  15. }  
需要调用的场景画板添加
  1. if(sp){   
  2. addChild(sp);   
  3. addChild(mc);   
  4. stage.addEventListener(Event.ENTER_FRAME,init);   
  5.   
  6. mc.graphics.clear();   
  7. }  
需要调用的场景原按钮不变
  1. mainBtnList.btn_a.addEventListener(MouseEvent.CLICK,go_a);   
  2. mainBtnList.btn_b.addEventListener(MouseEvent.CLICK,go_b);