How to load a SWF compiled by Flex into a SWF compiled by Flash CS4
I compiled a simple AS3 project 开发者_开发百科using Flex 3.5 (also tried Flex 4.1) to create a small swf which draws a simple red square on screen. Nothing too complex that requires special flashplayer support (see code below)
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);
}
}
}
and tried to load it into a AS2 swf I have compiled using Flash CS4. But that just didn't work. I don't get any errors when loading and the AS2 swf can load any swf, either compiled in AS2 or AS3 by Flash.
Any ideas?
Flex/Flash builder is only for as3. So you can't load it into an as2 swf. You can however create a new as3 file in flash and load both your as2 swf and your flex swf and position them accordingly. Loading swfs is easy in as3:
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);
}
精彩评论