2020/10/1
多场景画板的ActionScript代码
Adobe Animate应用多场景画板的方法,第一场景画板需要的代码
第一场景每个按钮需要添加clearHuaBan
需要调用的场景画板添加
需要调用的场景原按钮不变
- import flash.display.MovieClip;
- import flash.events.MouseEvent;
- var sp:MovieClip=new MovieClip();
- sp.graphics.lineStyle(0,0xEF856E,0.0);
- sp.graphics.beginFill(0x000000,0.0);
- sp.graphics.drawRect(1771,881,60,60);
- sp.graphics.endFill();
- sp.buttonMode=true;
- var mc:MovieClip=new MovieClip();
- function init(event:Event):void {
- mc.graphics.lineStyle(4);
- stage.addEventListener(MouseEvent.MOUSE_DOWN,onMD);
- stage.addEventListener(MouseEvent.MOUSE_UP,onMU);
- sp.addEventListener(MouseEvent.MOUSE_DOWN,SMD);
- sp.addEventListener(MouseEvent.MOUSE_UP,SMU);
- function onMD(event:MouseEvent):void {
- mc.graphics.moveTo(mouseX,mouseY);
- stage.addEventListener(MouseEvent.MOUSE_MOVE,onMM);
- }
- function onMU(event:MouseEvent):void {
- stage.removeEventListener(MouseEvent.MOUSE_MOVE,onMM);
- }
- function onMM(event:MouseEvent):void {
- mc.graphics.lineTo(mouseX,mouseY);
- }
- function SMD(event:MouseEvent):void {
- sp.startDrag(false);
- mc.graphics.clear();
- stage.removeEventListener(MouseEvent.MOUSE_DOWN,onMD);
- }
- function SMU(event:MouseEvent):void {
- sp.stopDrag();
- sp.x=0;
- sp.y=0;
- }
- }
- function go_a(e:MouseEvent){
- clearHuaBan();
- gotoAndPlay(1,“go_a”);
- }
- function go_b(e:MouseEvent){
- clearHuaBan();
- gotoAndPlay(1,“go_b”);
- }
- function clearHuaBan(){
- if(sp && stage.contains(sp) && stage.contains(mc) ){
- removeChild(sp);
- removeChild(mc);
- stage.removeEventListener(Event.ENTER_FRAME,init);
- }
- }
- if(sp){
- addChild(sp);
- addChild(mc);
- stage.addEventListener(Event.ENTER_FRAME,init);
- mc.graphics.clear();
- }
- mainBtnList.btn_a.addEventListener(MouseEvent.CLICK,go_a);
- mainBtnList.btn_b.addEventListener(MouseEvent.CLICK,go_b);