我有一個 AS3 專案,它的所有資產都使用[Embed]元資料標簽嵌入,因為我希望生成的 SWF 完全獨立,以便在 Internet 上移植。
問題:
檔案大小相當大,我希望在加載時顯示一個進度條,而不是顯示一個空白螢屏,直到它完全完成。我已經可以使用 Adob??e Animate (Flash Professional) 實作這一點,方法是使用帶有輕幀 1 和重幀 2的時間軸,其中包含嵌入大量資產的 MovieClip。
我正在嘗試切換到沒有 IDE 時間線的 Adob??e Flash Builder,但我不知道如何做與 Flash IDE 相同的事情。有沒有人對如何做到這一點有任何想法?
uj5u.com熱心網友回復:
選項№1。我選擇了一個,因為它更容易理解:外部加載器。一個輕量級SWF,其唯一目的是在加載重量級主模塊時顯示一些預加載資訊,如 % 或進度。
選項№2。有一個特定的元標記可以讓您模擬第 1 幀預加載器的行為。請記住,ASC2.0 編譯器(我假設為 AIR SDK)不支持,但僅ASC1.0編譯器(Flex SDK)支持。Flash Builder是Flex Builder的后代,所以我想這很好,但如果它不適合你,你首先應該檢查的是你的Flash Builder包含的編譯器版本。
因此,您的主要(您在設定中設定為檔案類的那個)類應該有一個metatag:
package
{
import flash.events.Event;
import flash.display.Sprite;
// Brace for the magic impact.
[Frame(factoryClass="Preloader")]
public class Main extends Sprite
{
public function Main()
{
// This is important, because at the moment of creation
// the instance is not attached to the stage.
if (stage) onStage(null);
else addEventListener(flash.events.Event.ADDED_TO_STAGE, onStage);
}
private function onStage(e:Event):void
{
removeEventListener(flash.events.Event.ADDED_TO_STAGE, onStage);
// This is the entry point of your actual application.
// The rest of the class goes normally from this point on.
然后,提到的預加載器類。它的名稱應該完全符合上面元標記中提到的條件。
package
{
import flash.display.DisplayObject;
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.events.ProgressEvent;
import flash.utils.getDefinitionByName;
// This class represents the multi-framed main timeline
// thus it should subclass the basic MovieClip.
public class Preloader extends MovieClip
{
public function Preloader()
{
// Subscribe to all necessary points to monitor the loading.
addEventListener(Event.ENTER_FRAME, onFrame);
loaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioError);
loaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgress);
}
private function ioError(e:IOErrorEvent):void
{
// Handle loading errors here.
}
private function onProgress(e:ProgressEvent):void
{
// Display loading progress here.
// Use e.bytesLoaded and e.bytesTotal values
// to calculate the % loaded and the overall loading progress.
}
private function onFrame(e:Event):void
{
// When the loading is finished, the main timeline,
// represented by Preloader class moves to the frame 2.
if (currentFrame == totalFrames)
{
stop();
onComplete();
}
}
// This method concludes the loading,
// cleans up the preloader itself
// and instantiates the Main class.
private function onComplete():void
{
removeEventListener(Event.ENTER_FRAME, onFrame);
loaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, ioError);
loaderInfo.removeEventListener(ProgressEvent.PROGRESS, onProgress);
// So, here's the thing. You don't import the Main class
// because if you import it, then it will be embedded into
// the Preloader, then it must be loaded before Preloader
// can be initialized, which kind of fails the whole idea.
// Thus, you don't import the Main class but obtain it
// via the other means, like the "getDefinitionByName" method.
// Again, the fully qualified class name is to be provided.
var aMain:Class = getDefinitionByName("Main") as Class;
stage.addChild(new aMain as DisplayObject);
// Remove this instance as it no longer needed for anything.
parent.removeChild(this);
}
}
uj5u.com熱心網友回復:
我找到了一個適用于 ASC2/AIR SDK 的解決方案。盡管他的示例預加載器擴展了 Sprite,并且我相信您需要擴展 MovieClip 才能使其作業,因為您需要第 2 幀。而且一旦完成加載,您還需要 gotoAndStop(2)。附加資訊在這里。伙計,當您的所有參考鏈接都通過 web.archive.org 時,這不是一個好兆頭!
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/418272.html
標籤:
