1

我是 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();
        }           

    }       

}
4

1 回答 1

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));
    } 
于 2013-06-03T20:10:40.803 回答