2 Replies Latest reply on Dec 17, 2009 1:49 AM by Zdenal

    accessing .sharedEvents

    Zdenal

      Hi folks,

      I want to use shared events and I am a bit confused how to access and use them.

       

      I have googled out some way how to access shared events (from pixelbox):

      // From the parent app where mySubApp is an instance of SWFLoader
      var e:Event = new Event('testFromParent');
      mySubApp.content.loaderInfo.sharedEvents.dispatchEvent(e);
      mySubApp.content.loaderInfo.sharedEvents.addEventListener( 'testFromSubApp' , _eventFromSubApp );

      // From the sub app
      var e : Event = new Event('testFromSubApp');
      this.systemManager.loaderInfo.sharedEvents.dispatchEvent(e);
      this.systemManager.loaderInfo.sharedEvents.addEventListener( 'testFromParent' , _testEventHandler);

      But!

      I cannot access

      mySubApp.content

      because I get

      SecurityError: Error #2121: Security sandbox violation: Loader.content:

      http://localhost/mainapp/mainapp.swf

      has no access to

      http://flex.domainB.com/subapp.swf. This can be bypassed by calling Security.allowDomain.
          at flash.display::Loader/get content()
          at mx.controls::SWFLoader/get content()
          at DisMarshall/onEmbeddedApplicationLoaderComplete()
          at DisMarshall/__embeddedApplicationLoader_complete()
          at flash.events::EventDispatcher/dispatchEventFunction()
          at flash.events::EventDispatcher/dispatchEvent()
          at mx.core::UIComponent/dispatchEvent()
          at mx.controls::SWFLoader/http://www.adobe.com/2006/flex/mx/internal::contentLoaderInfo_completeEventHandler()

       

      I already do call it in both applications like this:

      private function onPreinitialize(): void {
          Security.allowDomain("*");
      }

       

      It works if I set trustContent="true" upon the SWFLoader, but I have to deal with it without trusting the content. To summarize my questions:

       

      1. How should I correctly access the sharedEvents object without using trustContent=true?
      2. is there one sharedEvents object per SWFLoader?

       

       

       

       

        • 1. Re: accessing .sharedEvents
          Flex harUI Adobe Employee

          There is one sharedEvents dispatch between apps.  See the Marshall Plan info on the opensource wiki.  I think there is a visual in there.

           

          From the parent app, if you are using Marshall Plan configurations, you would use:

           

          mySubApp.swfBridge.dispatchEvent(e);

          mySubApp.swfBridge.addEventListener( 'testFromSubApp' , _eventFromSubApp );

           

          Otherwise, you'll have to do something like:

           

          mySubApp.getChildAt(0).contentLoaderInfo.sharedEvents.dispatchEvent(e);

          mySubApp.getChildAt(0).contentLoaderInfo.sharedEvents.addEventListener( 'testFromSubApp' , _eventFromSubApp );

           

          Alex Harui

          Flex SDK Developer

          Adobe Systems Inc.

          Blog: http://blogs.adobe.com/aharui

          • 2. Re: accessing .sharedEvents
            Zdenal Level 1

            Thanks for reply! It works

             

            Sure, there is wiki documentation about Marshall Plan, I have read lot of articles about it, including this one. But the image present there is probably outdated as SWFLoader has no contentHolder property in my SDK 3.4. Also there is very little up to date examples on this, that's why I am sometimes confused .