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 | 5 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.
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?
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?
i would avoid using the word “testes” in source code.
thx for the timer example
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?
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”);
}
}
}