Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
Adobe Flex SDK 3.2 (Release)
-
None
-
None
-
Affected OS(s): Mac
Affected OS(s): Mac OS 10.5
Browser: Safari
Language Found: English
Description
Steps to reproduce:
1. create Flex application, like
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="testMe(event)">
<mx:Script>
<![CDATA[
import nl.techtribe.events.TestEventMe;
private function testMe(e:Event):void
{ parent.dispatchEvent(new TestEventMe(TestEventMe.TEST)); }public function hello():void
{ txtMe.text = 'this is from flash'; } ]]
>
</mx:Script>
<mx:Label id="txtMe" text="Hello there" color="0xffffff"/>
</mx:Application>
2. create AS3 project with Flash, like
package {
import flash.display.Loader;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.IEventDispatcher;
import flash.events.IOErrorEvent;
import flash.net.URLRequest;
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;
import nl.techtribe.events.TestEventMe;
public class FlashTest extends Sprite
{
private var loader:Loader = new Loader();
public function FlashTest()
{ var context:LoaderContext = new LoaderContext(); context.checkPolicyFile = true; context.applicationDomain = ApplicationDomain.currentDomain; var urlReq:URLRequest = new URLRequest('FlexTest.swf'); loader.load(urlReq, context); configureListeners(loader.contentLoaderInfo); addChild(loader); }private function configureListeners(dispatcher:IEventDispatcher):void
{ trace('FLASH CONFIGURE LISTENERS:'+dispatcher); dispatcher.addEventListener(Event.INIT, initHandler); dispatcher.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler); }private function flexReady(e:Event):void
{ trace('FLASH flex is ready'); (e.target as MovieClip).application.hello(); }private function initHandler(e:Event):void
{ trace('FLASH INIT:'+e.target); (loader.content as MovieClip).addEventListener(TestEventMe.TEST, flexReady); }private function ioErrorHandler(e:IOErrorEvent):void
{ trace('FLASH IO ERROR:'+e); } }
}
3. create custom event in nl.techtribe.events
package nl.techtribe.events
{
import flash.events.Event;
public class TestEventMe extends Event
{
public static const TEST:String = 'test';
public function TestEventMe(type:String, bubbles:Boolean=false, cancelable:Boolean=false)
{ super(type, bubbles, cancelable); } }
}
4. publish both projects
5. change "parent.dispatchEvent(new TestEventMe(TestEventMe.TEST));" in "dispatchEvent(new TestEventMe(TestEventMe.TEST));" in the Flex application.
Actual Results:
the TestEventMe event is not visible in Flash (AS3) with (loader.content as MovieClip).addEventListener(TestEventMe.TEST, flexReady);
Expected Results:
loader.content references to the loaded Flex application, so because the dispatchEvent is dispatched in the "root" of the application I expect that can listen to it right away.
I also cannot do dispatcher.addEventListener(TestEventMe.TEST, flexReady) when configuring my EventListeners on the loaderInfo object. It needs to reference to the loaded object, but it doesn't do that.
Workaround (if any):
parent.dispatchEvent(new TestEventMe(TestEventMe.TEST)); works, so it implies that a flex wrapper is available, but I found on blogs that (loader.content as MovieClip).application.addEventListener(TestEventMe.TEST, flexReady); could work, but that didn't work with me.
It is not a major issue, while the workaround is not so difficult, but I lost a lot of time finding out that the Flex application had a wrapper around it and therefore I want more information if this is a bug otherwise more information on best practices loading flex apps into Flash CS3 / CS4 projects.