This content has been marked as final. Show 7 replies
You have to bubble up events from these components which the main file listens to then excecutes code when heard.
Events are the "best" way, since they provide loose coupling between your components.
If loose coupling is not an important goal in your application, you can access public properties and methods directly via the document model.
For example Application.application.myFunction() will call the public function myFunction() in the top-level application.
A bit more code in the component:
private var _appMain:Application = Application.application;
private function callMainAppFunc():void
var sValueFromMainAppFunction:String = _appMain.myFunction();
Thanks for the help. I got it working using ntsiii's method (which is more straight forward but maybe not good practice?) though the line
private var _appMain:Application = Application.application
gave me the error message:
1118: Implicit coercion of a value with static type Object to a possibly unrelated type mx.core:Application.
So i changed it to:
private var _appMain:* = Application.application
Which made it work, I don't really understand why.
private var _appMain : Object = Application.application ;
Oops, yes, I forgot, the app that I am working in now has compile time type checking turned off for various reasons.
"Application.application" actually returns an Object that contains an application.
using "*" is fine. Another option is to type it as the actual application data type which is the file name. This will give you code completion in FlexBuilder. So, if you main app is "MyApp.mxml", do:
private var _appMain:MyApp = MyApp(Application.application) ;
Thanks for everyone's help :-)