Flash ActionScript 3.0加载屏幕
问题描述:
我想要加载屏幕在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);
}
}
谁能帮助我?
感谢, 基督教
答
你需要把你的预加载在第1帧和你的项目的其余部分开始帧2.然后,你需要设置你的ActionScript设置,以便它知道加载所有的你第2帧上,而不是框架类1.
这里就是设置你需要改变:
- 文件> ActionScript设置...
- 更改“导出班FRA我说:”到2
- 更改‘默认链接:’要合并到代码
你的LoaderInfo现在应该返回文件加载正确的进步,而不是立即跳到完成。
谢谢!但是,我尝试了另一种方法。正如我在之前的文章中提到的,我的游戏中的每个关卡都是不同的场景。所以每个级别都使用其各自场景的第一帧。我曾尝试将Preloader放入它自己的场景中。游戏开始时,Preloader场景应该加载。然后在游戏加载之后,等级1应该开始。这没有用。我应该将所有不同的级别放入框架而不是场景中吗?或者有没有一种方法来实现带场景的Preloader? – 2012-03-10 09:32:18
此外,您可能想要通过第2帧上的getDefinitionByName实例化主文档类,因为在第2帧上拖动实际实例将导致在主时间轴上创建类型为“YourDocumentClass”的变量,这似乎强制它成为在第1帧中导出。 – Triynko 2012-11-15 23:27:37