如何将Flex编译的SWF加载到Flash CS4编译的SWF中

时间:2011-04-03 18:50:47

标签: flex actionscript flash-cs4 flash-builder

我使用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编译还是AS3编译的。

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

Flex / Flash构建器仅适用于as3。因此您无法将其加载到as2 swf中。但是,您可以在闪存中创建一个新的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);
}