我正在尝试让加载屏幕在 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);
}
}
有人可以帮我吗?
谢谢,克里斯蒂安