Pergunta

I have a SWf application built in flex 4. One part of the application relies on accessing a public variable ("step1") set at the application root, and is accessed with

var app:Object = FlexGlobals.topLevelApplication;
trace("step one is "+app.step1);

This, while not optimal, has worked fine. Now, hoever, I need to load this entire application into another application, and I can't figure out how to access my step1 variable any longer.

I have been loading the swf into the new parent application like so:

public var myLoader:Loader = new Loader();   
public var pizzaContainer:UIComponent = new UIComponent();

private var myUrl:URLRequest = new URLRequest("chickensoup.swf");

protected function application1_creationCompleteHandler(event:FlexEvent):void {
   myLoader.load(myUrl);                                   
   pizzaContainer.addChild(myLoader);                
   addElement(pizzaContainer);
}

And I have tried using FlexGlobals.topLevelApplication.pizzaContainer to no avail. What would be the method of acessing a public variable at the root of the loaded application?

Foi útil?

Solução

The SWF Loader has a content property which is available after the Loader Completed event has been raised, you can use this to access any exposed property in the loaded SWF

public var loadedSM:SystemManager;

// Initialize variables with information from
// the loaded application.
private function initNestedAppProps():void {
   loadedSM = SystemManager(myLoader.content);
}

Now try get values referencing like this:

loadedSM.application["lblOne"].text     
loadedSM.application["step1"]

Remember to make sure these are public variables!

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top