【问题标题】:How to load a SWF compiled by Flex into a SWF compiled by Flash CS4如何将 Flex 编译的 SWF 加载到 Flash CS4 编译的 SWF 中
【发布时间】:2011-07-28 18:00:37
【问题描述】:

我使用 Flex 3.5(也尝试过 Flex 4.1)编译了一个简单的 AS3 项目,以创建一个小的 swf,它在屏幕上绘制一个简单的红色方块。没有什么太复杂需要特殊的 flashplayer 支持(见下面的代码)

package  
{
    import flash.display.Sprite;

    /**
     * @author John Lindquist
     */
    [SWF(width="1024", height="768", frameRate="24")]
    public class EasingATimeline extends Sprite 
    {
        private var square:Sprite;
        private static const STEP_DURATION:Number = 1;

        public function EasingATimeline()
        {
            square = new Sprite();  
            square.graphics.beginFill(0xcc0000);
            square.graphics.drawRect(0, 0, 50, 50);
            square.graphics.endFill();

            square.x = 100;
            square.y = 50;

            addChild(square);
        }
    }
}

并尝试将其加载到我使用 Flash CS4 编译的 AS2 swf 中。但这只是行不通。加载时我没有收到任何错误,AS2 swf 可以加载任何 swf,无论是在 AS2 中编译还是由 Flash 编译的 AS3。

有什么想法吗?

【问题讨论】:

    标签: apache-flex actionscript flash-cs4 flash-builder


    【解决方案1】:

    Flex/Flash builder 仅适用于 as3。所以你不能将它加载到 as2 swf 中。但是,您可以在 flash 中创建一个新的 as3 文件并加载您的 as2 swf 和您的 flex swf 并相应地定位它们。在 as3 中加载 swfs 很容易:

    var as2:Loader = new Loader();
    as2.load(new URLRequest("myAS2Thing.swf"));
    as2.addEventListener(Event.COMPLETE, onDoneLoadingAS2);
    function onDoneLoadingAS2(e:Event):void{
     as2.x = 100;
     as2.y = 100;
      addChild(as2);
    }
    

    【讨论】:

    • 我原以为只要播放器支持它(AKA FP9 或更高版本),您应该能够加载任何 SWF。不过,我从未尝试过。查看kb2.adobe.com/cps/141/tn_14190.html 了解有关如何使用 AS2 和 AS3 加载外部 SWF 的信息。 AS2 SWF 如何知道它正在加载的 SWF 如何使用 AS3?为什么这很重要?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-22
    • 2013-02-18
    • 1970-01-01
    • 2023-01-11
    • 1970-01-01
    相关资源
    最近更新 更多