How to load Flash File in Flex 2

If you ever tried below code to load Flash(*.fla/*.swf) in Flex 2,you know <mx:SWFLoader /> tag ’s pretty limited.

  1. <mx:SWFLoader source="@Embed(source=sample.swf')" id="swf" x="0" y="0" width="400" height="580"/>


Then I tried another way like below source code,but I god the Error #1034–That can’t be converted from flash.display::Loader@ae341a1 to mx.core.IUIComponent.

  1. var re:URLRequest = new URLRequest("sample.swf");
  2. var loadDHoader = new Loader();
  3. loadDHoader.load(re);
  4. tile.addChild(loadDHoader);

I’ve spent time to fix it and found that the flash file can be loaded with below source code.

  1. var re:URLRequest = new URLRequest("sample.swf");
  2. var loader:SWFLoader = new SWFLoader ();
  3. loader.addEventListener(Event.COMPLETE, completeHandler);
  4. loader.load(re);
  5. function completeHandler(event:Event){
  6. addChild(loader);
  7. }

I’m not sure whether it is correct or not but hope will be helpful. BTW I found darronschall.com have supplied a better solution at here.

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • Reddit
  • Technorati
  • StumbleUpon
  • Twitter
RSS Enjoy this Post? Subscribe to Ntt.cc

RSS Feed   RSS Feed     Email Feed  Email Feed
You can leave a response, or trackback from your own site.

One Response to “How to load Flash File in Flex 2”

Leave a Reply