AS3链接类

时间:2013-06-03 18:59:40

标签: actionscript-3 flash class

我是AS3和班级的新手。将预加载器链接到其他类需要一些帮助。因此,如果main_class触发函数show_titleScene,预加载器将在播放前显示并加载数据。我尝试了很多但没有结果。我不知道如何链接。

coreEngine = main_class

public class coreEngine extends MovieClip  
{
    public var loading_screen:loading_scene;
    public var splash_screen:splash_scene;
    public var warning_screen:warning_scene;
    public var title_screen:title_scene;
    public var game_screen:game_scene;

    public function coreEngine() {
        show_loadingScene();
    }

    public function show_loadingScene() {
        loading_screen = new loading_scene();
        addChild(loading_screen);
    }

    public function show_splashScene() {
        splash_screen = new splash_scene();
        addChild(splash_screen);
    }       

    public function show_gameScene() {
        game_screen = new game_scene();
        addChild(game_screen);
    }       
}

loadingScene =预加载器类

public class loading_scene extends MovieClip 
{
    public var core:coreEngine;

    public function loading_scene() 
    {
        this.addEventListener(Event.ENTER_FRAME, loading);
    }

    function loading(e:Event):void{
        var total:Number = this.stage.loaderInfo.bytesTotal;
        var loaded:Number = this.stage.loaderInfo.bytesLoaded;

        loadingBar.loadingFill.scaleX = loaded / total;
        loader_txt.text = Math.floor((loaded / total) * 100) + "%";

        if (total == loaded){
            trace("LOADIN");
            this.removeEventListener(Event.ENTER_FRAME, loading);
            core.show_splashScene();
        }           

    }       

}

1 个答案:

答案 0 :(得分:0)

尝试在加载完成后调度事件,然后侦听该事件并继续使用该应用:

public function show_loadingScene() {
    loading_screen = new loading_scene();

    //Listen for the COMPLETE event on your loading screen, and goto the splash screen when it fires
    loading_screen.addEventListener(Event.COMPLETE,show_splashScreen);

    addChild(loading_screen);
}

public function show_splashScene(e:Event = null) {
    //remove the listener that you added to avoid memory leaks
    if(e && e.currentTarget){ //e.currentTarget is whatever you added the listener to, the loading screen in this case
        e.currentTarget.removeEventListener(Event.COMPLETE, show_splashScreen);
    }

    splash_screen = new splash_scene();
    addChild(splash_screen);
} 

    if (total == loaded){
        trace("LOADIN");
        this.removeEventListener(Event.ENTER_FRAME, loading);
        //dispatch a COMPLETE event
        dispatchEvent(new Event(Event.COMPLETE));
    }