Adobe Flash Builder:如何制作带有加载进度条的 SWF?

Adobe Flash Builder: How to make a SWF with a progress bar for loading itself?

我有一个 AS3 项目,它的所有资产都使用 [Embed] 元数据标签嵌入,因为为了在 Internet 上的可移植性,我希望生成的 SWF 完全独立。

问题:
文件大小相当大,我希望在加载自身时显示进度条,而不是在完全完成之前显示空白屏幕。我已经可以使用 Adob​​e Animate (Flash Professional) 实现这一点,方法是让 时间轴 具有轻帧 1 和重帧 2,后者具有嵌入大部分资产的 MovieClip。

我正在尝试切换到没有 IDE 时间轴的 Adob​​e Flash Builder,但我不知道如何做与 Flash IDE 相同的事情。有没有人知道如何实现这个?

选项 №1。我选择了一个,因为它更容易理解:外部加载器。一个轻量级 SWF,其唯一目的是在加载重量级主模块时显示一些预加载信息,如 % 或进度。

选项 №2。有一个特定的 metatag 允许您模拟第 1 帧预加载器的行为。请记住,ASC2.0 编译器(AIR SDK,我假设)不支持,但仅 ASC1 支持。 0 编译器(Flex SDK)。 Flash BuilderFlex Builder 的后代,所以我想这很好,但如果它不适合你,你首先应该检查你的 Flash Builder 的编译器版本。

因此,您的主要(您在设置中设置为文档 class 的那个)class 应该有那个 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.

然后,提到的预加载器class。它的名称应该完全符合上面 metatag 中提到的。

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);
        }
    }

我找到了 solution that works with ASC2 / AIR SDK. Although his example preloader extends Sprite, and I believe you need to extend MovieClip to make it work, since you need a frame 2. And you need a gotoAndStop(2) once it has finished loading itself. Additional information here。伙计,当你所有的参考链接都通过 web.archive.org!

时,这不是一个好兆头