Skip to main content
February 25, 2010
Question

Can custom events be handled and dispatched across the same security domain, diff app domain?

  • February 25, 2010
  • 1 reply
  • 438 views

Hi,

I am trying to create a portal which loads applications through SWFLoader which are in the same security domain but different application domains.

Can these scenarios be handled?

1. sub-application dispatch custom event and be handled by the host application (portal)?

2. host application dispatch custom event and be handled by sub-application?

I am currently using the following for simple events:

//from dispatching application

systemManager.getSandboxRoot().dispatchEvent(new MouseEvent("click");

//receiving application

systemManager.getSandboxRoot().addEventListener(MouseEvent.CLICK,clickHandler);

I need to be able to pass data along with the custom event within the same security domain (diff app domain), this is why I need custome events.

Can this be done? Would I have to create an RSL that contains the custom event package and import it to the separate applicaitons?

Thank you for your advise 🙂

Regards,

/Fatima

This topic has been closed for replies.

1 reply

February 25, 2010

My applications look as follows. There is a host application that loads a separate application as a sibling in a different applicaiton domain but same security domain. They need to listen to a custom event as follows:

HOST APPLICATION:

-------------------------------

<?xml version="1.0" encoding="utf-8"?>

<mx:Application

xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"

creationComplete="init()"

>

<mx:Script>

<![CDATA[

import mx.controls.Alert;

import myEvents.SelectedEvent;

public function init():void

{

sibling.loadForCompatibility =

true;

sibling.trustContent =

true;

sibling.load(

"http://localhost:8080/sandboxtest/output/sandboxsiblingtest.swf");

systemManager.getSandboxRoot().addEventListener(SelectedEvent.SELECTED_EVENT, changeLabel);

}

public function changeLabel(event:SelectedEvent):void{

titleLabel.text = event.selectedItem;

}

]]>

</mx:Script>

<mx:SWFLoader id="sibling" x="10" y="10" width="397" height="282"/>

<mx:Label id="titleLabel" text="text" x="415" y="10" width="260" height="27"/>

</mx:Application>

LOADED APPLICATION: //sandboxsiblingtest.mxml

-----------------------------------------------------------------------------------

<?xml version="1.0" encoding="utf-8"?>

<mx:Application

xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

<mx:Script>

<![CDATA[

import myEvents.SelectedEvent;

public function clickEvent(e:Event):void

{

var selectEvent:SelectedEvent = new SelectedEvent(SelectedEvent.SELECTED_EVENT,"Hello from sandbox Sibling");

systemManager.getSandboxRoot().dispatchEvent(selectEvent);

}

]]>

</mx:Script>

<mx:Button width="164" label="Click to Send Event to parent" click="clickEvent(event)" labelPlacement="left"/>

</mx:Application>

EVENT CLASS: // SelectedEvent.as

----------------------------------------------------------------------------------------

package

myEvents

{

import flash.events.Event;

public class SelectedEvent extends Event

{

  public var selectedItem:String;

  public static const SELECTED_EVENT:String = "SELECTED_EVENT";

public function SelectedEvent(type:String, selectedItem:String)

{

  super(type);

  this.selectedItem = selectedItem;

}

override public function clone():Event{

  return new SelectedEvent(type,selectedItem);

}

}

}

When I run it, I get the following error:

TypeError: Error #1034: Type Coercion failed: cannot convert myEvents::SelectedEvent@a33c389 to myEvents.SelectedEvent.
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at sandboxsiblingtest/clickEvent()[sandboxsiblingtest.mxml:11]
at sandboxsiblingtest/___sandboxsiblingtest_Button1_click()[sandboxsiblingtest.mxml:15]

Any Ideas?

Thank you so much for the help :-)