1

我正在尝试让加载屏幕在 Flash 中工作。这就是我的项目的设置方式:

  • 所有游戏都发生在“Layer 1”中,该层设置为许多不同的场景:“Level 0”、“Level 1”等。它的代码在“.as”文件中运行

  • 我尝试在新层“预加载器”中实现一个简单的加载屏幕(带有进度条)。它的代码在层的“Actions”中运行。

我意识到将 Preloader 的代码放在它的“Actions”中并不是最好的主意,因为一开始我的第 1 层的“.as”文件加载级别为 0。所以“Preloader”和“Layer 1”层试图同时运行。这引起了问题。

现在我已经尝试将 Preloader 放到它自己的场景中。那是行不通的。

这是我尝试用于预加载器的代码 - “场景”版本:

        // This function loads the Preloader
    public function loadPL(event:Event) {
        // Load the Scene associated with the Preloader
        this.gotoAndStop(1, "PL");


        // Prevent the MovieClip (game) from playing right away
        stop();

        // Add an EventListener that calls the 'loading()' function
        this.addEventListener(Event.ENTER_FRAME, loadingPL);


    } // End of 'loadPL()' method               

        // 'loading()' function
            // This function calculates how much of the game has been loaded vs. how much data
            // the game contains. The loading progress bar is resized accordingly.
        public function loadingPL(e:Event):void{
            // How much data does the game have in all?
            var totalData:Number = this.stage.loaderInfo.bytesTotal;

            // How much data has been loaded so far?
            var loadedData:Number = this.stage.loaderInfo.bytesLoaded;

            // Scale the 'plBarIns' according to the loadedData:totalData ratio
            plBarIns.scaleX = loadedData/totalData;

            // If the 'loadedData' == 'totalData' (all of the game's data has been loaded), allow
                // the game to play
            if (loadedData == totalData) {
                play();

                // Remove the EventListener that calls the 'loading()' function. It's not needed now
                this.removeEventListener(Event.ENTER_FRAME, loadingPL);
            }
        }

有人可以帮我吗?

谢谢,克里斯蒂安

4

1 回答 1

2

您需要将预加载器放在第 1 帧,并让项目的其余部分从第 2 帧开始。之后,您需要设置 ActionScript 设置,以便它知道将所有类加载到第 2 帧而不是第 1 帧。

以下是您需要更改的设置:

  1. 文件 > 动作脚本设置...
  2. 将“框架中的导出类:”更改为 2
  3. 将“默认链接:”更改为合并到代码中

您的 loaderinfo 现在应该返回文件加载的正确进度,而不是立即跳转到完成。

于 2012-03-09T06:58:58.993 回答