Skip to main content
January 22, 2010
Answered

Loading a sub-application in same application domain as main app sibling

  • January 22, 2010
  • 1 reply
  • 1697 views

Hi,

I am creating a portal application which loads applications in their own application domain different from the main app. Basically what I am trying to do is the following:

-Portal  -- Main ApplicationDomain

   - SubApp1 - new AppDomain

   - SubApp2 - same AppDomain as SubApp1

SubApp1 and SubApp2 could then call each other's properties and change their values.

I tried the following:

var loaderContext:LoaderContext = new LoaderContext();

loaderContext.securityDomain = SecurityDomain.currentDomain;

loaderContext.applicationDomain =

new ApplicationDomain();//new app domain

//--SubApp1

swfLoader1SubApp1 =

new SWFLoader();

swfLoader1SubApp1.loaderContext =loaderContext;

panel1.addChild(swfLoader1SubApp1);

//--SubApp2

swfLoader2SubApp2 =

new SWFLoader();

swfLoader2SubApp2 .loaderContext = swfLoader1SubApp1.loaderContext;

panel2.addChild(swfLoader2SubApp2);

When I try to change values in each other's values, only SubApp1 one can change the value of the property on SubApp2.  SubApp2 gives me an error as follows when accessing SubApp1 property:

ReferenceError: Error #1069: Property treeTitle not found on SubApp2 and there is no default value.

I am trying have them reference each other's propertie's as follows:

//SubApp2 calling SubApp1 --- DOES NOT WORK -- GIVES ABOVE ERROR

public function setLabel():void //some function that gets called when a button is clicked on SubApp2

{

Application.application.treeTitle.text =

"dummy value";   //treeTitle is a member of SubApp1

}

The other way around works: SubApp1 calling SubApp2  -- THIS WORKS FINE

// Event handler for the Tree control change event.

public function treeChanged(event:Event):void {

selectedNode=Tree(event.target).selectedItem

as XML;

Application.application.titleBar.text = selectedNode.@label;

}

What am I doing wrong? Any ideas are greatly appreciated 🙂

Thank you.

This topic has been closed for replies.
Correct answer Darrell_Loverin

Hi Darrell,

Yes, this is correct. they are modifying each other's property value.

Are you saying that I should use systemManager.document?

Thanks.


No, I got mixed up in what you were trying to achieve. systemManager.document will allow each application to update its own "treeTitle.text". If you want to modify objects from one application that live in another application then I would try the following technique. Use the top-level application, Application.application, as a message dispatcher to relay messages from SubApp1 to SubApp2 and vice-versa. First you need to create a custom event that tells what application is targeted, "SubApp1" or SubApp2" and the value to set into "treeTitle.text". Both SubApp1 and SubApp2 should add listeners for the custom Event on Application.application. When the event listeners are called they check if the event is for them. If so, they update their "treeTitle.text" to the value given in the event. Otherwise they do nothing. In each application you would dispatch a message like this:

Application.application.dispatchEvent(customEvent);

In Flex4, using FlexGlobals.topLevelApplication instead of Application.application.

-Darrell

1 reply

Inspiring
January 22, 2010

Application.application gets its data from a static variable. The first application loaded into a top-level application domain will be the value returned by Application.application.

Try using systemManager.application instead.

-Darrell

January 22, 2010

Hi,

Thank you for the suggestion. I am trying to understand where to change.

My sub-application code is as follows:

import mx.core.Application;

public function setLabel():void

{

     Application.application.treeTitle.text =

"dummy value";

}

Based on your suggestion, I changed as follows:

import mx.core.Application;

import mx.managers.SystemManager;

public function setLabel():void

{

     systemManager.application.treeTitle.text =

"dummy value";

}

But there is an error on the line as follows:

1119: Access of possibly undefined property application through a reference with static type mx.managers:ISystemManager.

Am I missing something? Thank you so much for your advice.

--Fatima

Inspiring
January 22, 2010

Seems like you imported mx.managers.SystemManager instead of mx.managers.ISystemManager.

-Darrell