AS3重复了MovieClip

时间:2015-08-14 14:11:34

标签: actionscript-3 flash addchild

在我的应用程序中,我将动画片段从库导入舞台,如下所示:

package {

import flash.display.*;
import flash.text.*;
import flash.events.*;
import flash.ui.Keyboard;
import flash.ui.Mouse;
import flash.display.MovieClip;

public class MainTimeline extends MovieClip {

    //Variabili
    public var VFullscreen: int = 1;

    //Import var        
    public var VTerminal: Terminal = new Terminal();
    public var nTerminal:String;

    public function MainTimeline(): void {

        stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;

        //Import

        //Terminal
        VTerminal.x = 288;
        VTerminal.y = 384;
        stage.addChild(VTerminal);


        //Event Listeners
        //addEventListener(MouseEvent.CLICK, fl_BringToFront);
        VTerminal.addEventListener(MouseEvent.MOUSE_DOWN, fl_WindowDrag);
        VTerminal.addEventListener(MouseEvent.MOUSE_UP, fl_WindowDrop);
    }

    //public functions

    //Gestione Fullscreen

    public function fl_Fullscreen(event: MouseEvent): void {
        switch (VFullscreen) {
            case 0:
                stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;
                VFullscreen = 1;
                break;
            case 1:
                stage.displayState = StageDisplayState.NORMAL;
                VFullscreen = 0;
                break;
        }
    }

    public function fl_FSCheck(event: Event): void {
        if (stage.displayState == StageDisplayState.NORMAL) {
            VFullscreen = 0;
        }
        if (stage.displayState == StageDisplayState.FULL_SCREEN_INTERACTIVE) {
            VFullscreen = 1;
        }
    }

    //Primo Piano Finestre
    public function fl_BringToFront(event: MouseEvent): void {
        this.addChild(event.currentTarget as DisplayObject);
    }


    public function fl_WindowDrag(event: MouseEvent): void {
        event.currentTarget.startDrag();
        nTerminal = event.currentTarget.name.toString();
        trace(nTerminal);
    }

    public function fl_WindowDrop(event: MouseEvent): void {
        event.currentTarget.stopDrag();
    }

    //Chiusura
    public function fl_Close(event: MouseEvent): void {
        stage.nativeWindow.close();
    }

    //Apertura/Chiusura Terminal
    public function fl_Terminal(event: MouseEvent): void {
        if (contains(VTerminal)) {
            removeChild(VTerminal);
        } else {
            VTerminal.x = 288;
            VTerminal.y = 320;
            addChild(VTerminal);
        }
    }

}

}

但我有一个我从未见过的奇怪的虫子。它有两次相同的MC,在运行时,当我拖放它时,我可以看到2个名为instance8的MC和一个instance45。我不知道如何解决这个问题。 提前谢谢。

TERMINAL CLASS

package {

import flash.display.MovieClip;
import flash.events.*;
import flash.ui.Keyboard;
import flash.text.TextField;


public class Terminal extends MovieClip {

    public var version: String = "Verison 0.0.1 a";

    public function Terminal(event: Event) {
        //Varie
        nome.text = "terminal";
        vOut.text = version;

        //Animazioni
        loader0.gotoAndPlay(1);
        loader1.gotoAndPlay(25);
    }

}

}

1 个答案:

答案 0 :(得分:-1)

据我所见,声明

//Primo Piano Finestre
public function fl_BringToFront(event: MouseEvent): void {
    this.addChild(event.currentTarget as DisplayObject);
}

当mouseDown和mouseUp事件结束时,mouseEvent.click事件将触发,因此你将获得另一个实例