Flash Actionscript 3.0加载屏幕

时间:2012-03-09 05:50:34

标签: actionscript-3 flash loading preloader scene

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

  • 所有游戏都发生在“第1层”中,它被设置为许多不同的场景:“等级0”,“等级1”等。其代码在“.as”文件中运行< / p>

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

我意识到将Preloader的代码放在“Actions”中并不是最好的主意,因为我首先将Layer 1的“.as”文件加载到0级。因此“预加载器”和“第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);
            }
        }

有人可以帮助我吗?

谢谢, 基督教

1 个答案:

答案 0 :(得分:2)

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

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

  1. 文件&gt; ActionScript设置...
  2. 将“将帧中的类导出:”更改为2
  3. 将“默认链接:”更改为合并为代码
  4. 您的loaderinfo现在应该返回文件加载的正确进度,而不是立即跳转到已完成。