This content has been marked as final. Show 1 reply
I had this same problem, and I couldn't find anything on the Internet to answer my question.
Your setup is probably very similar to mine, in that I had 1 flex app that would load other flex apps into a SWFLoader. The external/loaded SWF files were located on the same domain as the parent/loader (For other domains see Note at bottom). I needed to access variables and functions that I had defined in the parent/loader from the child/loaded SWF and vice-versa. I found the solution after hours of trial and error.
If you define variables and functions in <mx:Script> tags inside your <mx:Application> tag, the variables and functions are actually defined as properties and methods of the application object. For example: If you were to define a variable public var test_var_1:String = "Test Value 1"; in your parent/loader SWF, you would be able to access it from the child/loaded SWF by accessing the parent/loader's application object. To do so you would call Application.application.test_var_1. Application.application returns the top most application object (which happens to be from the parent/loader). This will give you access (if you have permission) to access the application object's properties and methods. To go the other way would be like this: swf_loader.content.application.test_var_2. (Where swf_loader is the id of the SWFLoader and test_var_2 is a variable that is defined in the application of the child/loaded SWF file.)
From child to parent: Application.application.<var or func from parent>
From parent to child: <id of SWFLoader>.content.application.<var or func from child>
As I mentioned it took me hours to figure this out since I could find no documentation or help on how to cross-script. I only found articles that said it could be done, but not how. I am responding to this post in hopes of helping someone else looking for the same thing that I was looking for.
Note: If the child/loaded SWF files are on another domain, you will need to allow access for cross-scripting through the Security.allowDomain static method. I have not tried this, as it is unnecessary for the application that I am building. For more details on cross-scripting security Click Here