“Be inspired, enjoy your work, keep learning and never forget to play.” — gskinner

Load an external flex swf into a flash project and communicate with him.

Posted: April 15th, 2008 | Author: Ivan Valadares | Filed under: Actionscript3, Adobe Flex, Code, Events | 6 Comments »

Loading the swf is easy; you can make a normal loader and load it. And now the tricky part, if the swf is a swf flash file you can call the function you want, but in flex, because it have 2 frames, (first frame is just for loading), you need to wait until frame 2 is available, you can’t also access directly to a swf, you have to refer application before, so there’s the code:

you can also add Event Listener's to myClip.application , like myClip.addEventLIstener(“ON_CHANGE”,function), so by this way you can embed flex swf into an flash application and communicate with him by calling function and receiving events.


6 Comments on “Load an external flex swf into a flash project and communicate with him.”

  1. 1 kino said at 12:26 am on May 24th, 2008:

    Omnipotence is an idea. Does Wittgenstein really believe that Foucault says that justice is separate from the universe? Does Hume really believe that I agree with Locke on this belief? Skepticism proves Reductionism.

    My philosophy teacher says that consciousness can be inconsistent with reality, but my life can be thought of as my consciousness. If existence breaks down society’s beliefs about thought, is it true that an outside influence breaks down epistemology? I’m wondering whether or not according to Kierkegaard, religion can be similar to Postmodernism. Thought leads inevitably to society’s beliefs about my consciousness. If existence can be without a connection to Existentialism, is it true that Descartes says that the Prisoner’s Dilemma cannot be separate from an idea?

  2. 2 DeepBlock said at 2:36 am on June 2nd, 2008:

    is it possible to use the uiloader to load an external swf compiled with flex 3 into a swf compile with flash cs3 at runtime. is there any principle to folow?

  3. 3 drew said at 12:44 pm on February 6th, 2009:

    i would avoid using the word “testes” in source code.
    thx for the timer example

  4. 4 Tom said at 12:41 pm on April 7th, 2009:

    As soon as I try to load a SWF created with Flex 3 in a Flash CS3 project using a Loader instance, I get the following error:

    TypeError: Error #1034: Type Coercion failed: cannot convert xxx@40cd4d01 to mx.core.IUIComponent. at mx.managers::SystemManager/initializeTopLevelWindow()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\managers\SystemManager.as:3188] at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::docFrameHandler()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\managers\SystemManager.as:3064] at mx.managers::SystemManager/docFrameListener()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\managers\SystemManager.as:2916]

    Do you have any idea how I can resolve this, in order to use SWFs created with Flex in a Flash CS3 project? Or isn’t this possible at all?

  5. 5 Cihan Polat said at 4:03 pm on April 10th, 2009:

    I think this version is handier

    package {
    import flash.display.Loader;
    import flash.display.MovieClip;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.TimerEvent;
    import flash.net.URLRequest;
    import flash.utils.Timer;

    [SWF(width='1024',height='768',backgroundColor='0x000000',frameRate='25')]

    public class testes extends Sprite
    {

    private var _swfTimer:Timer;
    private var _loader:Loader;

    public function testes()
    {
    _loader = new Loader();
    _loader.load(new URLRequest(“Gui.swf”));
    _loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loadIt);
    addChild(_loader);
    }

    private function loadIt(e:Event):void
    {
    var myclip:MovieClip = _loader.content as MovieClip;
    if(myclip.application == null )
    myclip.addEventListener( “applicationComplete”, onAppComplete );
    else
    onAppComplete();
    }

    private function onAppComplete(e:Event=null):void
    {
    var myclip:MovieClip = _loader.content as MovieClip;

    // call the function here eg: traceFunction(“Hello World”)
    myclip.application.traceFunction(“Hello World”);

    }

    }
    }

  6. 6 jorge luis said at 4:43 pm on March 9th, 2011:

    Of course!, listen to the appcomplete dispatch, good idea.

    Thank you for sharing.


Leave a Reply