im writting an actionScript class to handle my web service calls. When i retrieve a result i want to call a setter method in my main mxml application. My problem is that i dont know how to access the methods in the actionScript section of my main mxml class from my actionscript class, any ideas?
im writting an actionScript class to handle my web service calls. When i retrieve
Share
David is right — while you can access the public members of your Application.mxml object statically and from anywhere in your application, design-wise that’s a bit of a no-no. It’s better to strive for loose coupling between your objects, and the way that’s done in the Flex idiom is generally to extend EventDispatcher and to dispatch events. So for example, your WebService wrapper might look something like this:
… and your Main.mxml file like this:
In this case, the end result is the same — completing the web-service load triggers the function in Main.mxml. But notice how
mywrapper_webServiceComplete()is declared privately — it’s not called directly byMyWrapperClass. Main.mxml simply subscribes (withaddEventListener()) to be notified when MyWrapperClass is finished doing its work, and then does its own work; MyWrapperClass knows nothing about the details of Main.mxml’s implementation, nor does Main.mxml know anything about MyWrapperClass other than that it dispatches awebserviceCompleteevent, and exposes a publicdoWork()method. Loose coupling and information hiding in action.Good luck!