1 Reply Latest reply on May 10, 2007 8:09 PM by natiupiru

    Cross-scripting

    CourtN
      Okay... I have reviewed all the help files on this topic. I have also search the internet for further examples on this topic and I can't find anything about it.

      Basically all I am doing is loading a swf file dynamically. The flex app gets is list of swfs to load from a webservice. From there I want to configure or set the vars in each swf. Each independant swf needs to get the location of the wsdl from the parent flex app.

      I've got localConnection going... from the loaded swf sends a LC to the parent requesting a method called "LoadVars". That method then sends a LC with an object(argument) to the loaded swf requestion that has the wsdl configuration info. That method takes the object and sets it locally for the load swf app to use.

      This is method works however, doesn't seem to be very solid.

      Help?!?

      Is there a way to access vars from the loaded swf to set them?
        • 1. Cross-scripting
          natiupiru
          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.)

          To summarize:
          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