2012-08-11 65 views
0

我有一個遊戲,我已經在兩個文件中運行,一個preloader和一個swf。當我一起使用這兩個文件時,它們工作正常,但是一些Flash門戶只需要一個SWF,所以我試圖找到最短路徑的方式將其轉換爲僅使用一個。如何將帶有Document類的雙文件預加載器和遊戲swf轉換爲單個swf?

遊戲swf使用包含包,類構造函數和大量函數的文檔類,並且運行良好。我在我的代碼中引用了舞臺上的很多movieclip。該代碼是這樣的(有刪節):

package { 

    import flash.display.MovieClip; 
    import flash.events.MouseEvent; 
... 
    public class Game extends MovieClip {  
    var EnemyArray:Array; 
    var HeroArray:Array; 
... 
public function Game() { // class constructor 
     EnemyArray = new Array(); 
     addEventListener(Event.ENTER_FRAME,onEnterFrame); 
        mainRestartButton.addEventListener(MouseEvent.CLICK, RestartLevel); 
... 
} 
public function KeyPressed(event:KeyboardEvent):void 
    { 
     if (event.keyCode == Keyboard.SPACE) 
     { 
     attack(); 
... 
      } 
} // End of class 
} // End of package 

我也有另一個SWF,我的預加載,它在第1幀以下代碼:

import flash.display.Loader; 
import flash.net.URLRequest; 
import flash.events.ProgressEvent; 
import flash.events.Event; 

var myLoader:Loader = new Loader(); 
myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onLoading); 
var myURL:URLRequest = new URLRequest("Game.swf"); 
myLoader.load(myURL); 
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete); 

function onLoading(event:ProgressEvent):void { 
    var loaded:Number = event.bytesLoaded/event.bytesTotal; 
    percent_txt.text = "Loading: " + (loaded*100).toFixed(0) + "%"; 

} 

function onComplete(event:Event):void { 
    myLoader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, onLoading); 
    myLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onComplete); 
    this.addChild(myLoader); 
} 

我經歷過的色域在線解決方案,並沒有一個似乎與我的代碼設置方式,如:How to create Preloader in AS3

我試過他的選項1通過採取我的文檔類中的所有代碼,而不是包和構造函數,並粘貼它到幀2.然而它返回「錯誤#1009:Cann ot訪問空對象引用的屬性或方法。「對於在舞臺上的物品,如任何引用:

mainRestartButton.addEventListener(MouseEvent.CLICK, RestartLevel); 

正如他提到,「這種運作良好,如果你的方式組織你的項目的大部分資產(圖像等)是在Flash IDE Library並且不會加載到第一幀(您可以檢查每個庫項目的屬性)。「我的項目不是以這種方式組織的。

什麼是最簡單的方法來重新組織我的FLA /代碼,以便他們可以在單個swf中加載預加載器?

非常感謝您的時間和幫助!

回答

0

我用的是FlashDevelop(無FLA文件),所以我不知道這是否會爲你工作,但我使用該解決方案所描述here.

+0

謝謝,我發現這一個了。我還沒有弄清楚,但我會繼續嘗試! – FriendlyFlashAmateur 2012-08-23 06:01:32