2012-03-09 75 views
1

我想要加載屏幕在Flash中工作。這是我的項目是如何設置:Flash ActionScript 3.0加載屏幕

  • 所有的遊戲中出現「圖層1」,它被設置成許多不同的場景:「0級」,「1級」等。其代碼運行在「.as」文件中

  • 我試圖在一個新圖層「Preloader」中實現一個簡單的加載屏幕(帶有進度條)。其代碼運行在圖層的「操作」中。

我意識到,把預加載的代碼在其「操作」是不是最好的辦法,因爲我有1層的「至於」文件加載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); 
      } 
     } 

誰能幫助我?

感謝, 基督教

回答

2

你需要把你的預加載在第1幀和你的項目的其餘部分開始幀2.然後,你需要設置你的ActionScript設置,以便它知道加載所有的你第2幀上,而不是框架類1.

這裏就是設置你需要改變:

  1. 文件> ActionScript設置...
  2. 更改「導出班FRA我說:」到2
  3. 更改‘默認鏈接:’要合併到代碼

你的LoaderInfo現在應該返回文件加載正確的進步,而不是立即跳到完成。

+0

謝謝!但是,我嘗試了另一種方法。正如我在之前的文章中提到的,我的遊戲中的每個關卡都是不同的場景。所以每個級別都使用其各自場景的第一幀。我曾嘗試將Preloader放入它自己的場景中。遊戲開始時,Preloader場景應該加載。然後在遊戲加載之後,等級1應該開始。這沒有用。我應該將所有不同的級別放入框架而不是場景中嗎?或者有沒有一種方法來實現帶場景的Preloader? – 2012-03-10 09:32:18

+0

此外,您可能想要通過第2幀上的getDefinitionByName實例化主文檔類,因爲在第2幀上拖動實際實例將導致在主時間軸上創建類型爲「YourDocumentClass」的變量,這似乎強制它成爲在第1幀中導出。 – Triynko 2012-11-15 23:27:37