David is right - as long as you can publicly publish your Application.mxml objects anywhere in your application, the design is a bit of a no-no. Itβs better to strive for a free connection between your objects, and how this is done in the Flex idiom usually extends to EventDispatcher and event dispatch. For example, your WebService shell might look something like this:
public class MyWrapperClass extends EventDispatcher { [Event(name="webserviceComplete", type="flash.events.Event")] public function MyWrapperClass(target:IEventDispatcher=null) { super(target); } private function handleWebServiceLoadComplete(event:ResultEvent):void { dispatchEvent(new Event("webserviceComplete")); } public function doWork():void {
... and your Main.mxml file as follows:
<mx:Script> <![CDATA[ private function app_creationComplete(event:Event):void { var myWrapper:MyWrapperClass = new MyWrapperClass(); myWrapper.addEventListener("webserviceComplete", mywrapper_webServiceComplete, false, 0, true); myWrapper.doWork(); } private function mywrapper_webServiceComplete(event:Event):void {
In this case, the end result is the same - completing the download of the web service calls the function in Main.mxml. But notice how mywrapper_webServiceComplete() declared confidential - it is not called directly by MyWrapperClass . Main.mxml simply signs (with addEventListener() ) to receive MyWrapperClass shutdown notifications, and then does its own work; MyWrapperClass knows nothing about the details of the implementation of Main.mxml, nor does Main.mxml know anything about MyWrapperClass, except that it dispatches the webserviceComplete event and provides the public doWork() method. Free communication and information hiding in action.
Good luck
source share