开发者

How to embed SWF in Flex and get the timeline code in the embedded SWF?

开发者 https://www.devze.com 2022-12-31 23:28 出处:网络
my client want to have all resources embedded into the Main SWF which i create with Flex. The UI itself origins form a .FLA that must have timeline actionscript (AS3). After I embed the SWF there seem

my client want to have all resources embedded into the Main SWF which i create with Flex. The UI itself origins form a .FLA that must have timeline actionscript (AS3). After I embed the SWF there seems to be NO timeline AS in the embedded SWF. Is this possible to solve?

I Embed like this:

public var templ: TemplateBase;


[Embed(source="images/template_banner.swf", mimeType="application/octet-stream")]
public var TemplateSWF:Class; 

...

var ba : ByteArray = new TemplateSWF() as ByteArray;
var l : Loader = new Loader();
l.loadBytes(ba); 
l.addEventListener(Event.ADDED_TO_STAGE, onTemplateAdd);
开发者_开发知识库addChild(l);

private function onTemplateAdd(evt:Event):void{
  templ  = evt.target.contentLoaderInfo.content;
}

In template_banner.swf there is a stop(); in frame 1, and some code in frame 2. I trace in both frames but nothing is showing in the Flex (4) debugger. After the swf is added to stage I do play() in the TemplateBase class.

The thing is that play and all the AS code in the loaded SWF is totally dead.

My question is: Is there a way to keep the timeline AS code in the embedde SWF? And yes I need to embed the SWF into the Flex main file :/

Thanks, Rob


From what I'm seeing in the code, you are doing loadBytes which is asynchronous... and then waiting to the ADDED_TO_STAGE, and in the event listener you are accessing the content...

Because the loadBytes is asynchronous, you should wait for the loading to complete. In the complete listener you should access the loaded content. I would totally avoid the ADDED_TO_STAGE.

do it like this:

public var templ: TemplateBase;

[Embed(source="images/template_banner.swf", mimeType="application/octet-stream")]
public var TemplateSWF:Class; 

var ba : ByteArray = new TemplateSWF() as ByteArray;

var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
loader.loadBytes(ba); 

private function completeHandler(event:Event):void {
  templ  = evt.target.contentLoaderInfo.content;  
}
0

精彩评论

暂无评论...
验证码 换一张
取 消