1

読み込み画面を Flash で動作させようとしています。これが私のプロジェクトのセットアップ方法です。

  • すべてのゲームは、「レベル 0」、「レベル 1」などのさまざまなシーンに設定された「レイヤー 1」で発生します。そのコードは「.as」ファイルで実行されます。

  • 新しいレイヤー「プリローダー」にシンプルなロード画面(プログレスバー付き)を実装してみました。そのコードは、レイヤーの「アクション」で実行されます。

最初にレイヤー 1 の「.as」ファイルをレベル 0 でロードしたため、プリローダーのコードを「アクション」に配置することは最善のアイデアではなかったことがわかりました。そのため、「プリローダー」レイヤーと「レイヤー 1」レイヤーは同時に実行しようとしました。これにより問題が発生しました。

今、プリローダーを独自のシーンに入れてみました。それは機能していません。

プリローダーに使用しようとしたコードは次のとおりです-「シーン」バージョン:

        // 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 で開始する必要があります。その後、フレーム 1 ではなくフレーム 2 ですべてのクラスをロードするように ActionScript 設定をセットアップする必要があります。

変更する必要がある設定は次のとおりです。

  1. ファイル > ActionScript 設定...
  2. 「フレーム内のクラスのエクスポート:」を 2 に変更します。
  3. 「デフォルトのリンケージ:」を「コードに統合」に変更

loaderinfo は、すぐに完了にジャンプするのではなく、ファイルの読み込みの適切な進行状況を返すようになりました。

于 2012-03-09T06:58:58.993 に答える