Loading data across domains
For security reasons, a Macromedia Flash movie is not permitted to load data from a different Internet domain. Attempts to access cross-domain data or data returned to Macromedia Flash Player from another domain will be ignored by the Macromedia Flash Player. SeeAdditional information to find specific information on domain comparison.
Note:Macromedia Flash Player release 6r47 did not allow an HTML page on the web to load a SWF file that was stored on the local machine (for example on a CD-ROM or local hard drive). This functionality has been restored in Macromedia Flash Player 6 release r65 (6,0,65,0) and above. For SWF files accessing internet based content these rules still apply.
If a Flash web application needs to access information from a different domain, a developer can use one of two recommended methods on the server-side to give Flash access to this data.See the table below for an overview of each method.
| Server-side proxy method | Requirements: You must be able to upload and run a server-side script on a server in the same domain as the Flash movie. In this method, the Flash movie accesses the script, which loads the information, retrieves it, and returns the information back to the Flash movie. This method is best if the server hosting the data is not under your control (for example, a public XML feed). |
| Shim SWF method | Requirements: You must be able to upload a SWF to the server hosting the data source. The method loads a "Shim SWF", hosted in the same domain as the data source. The shim loads the information, and the information is passed from the shim SWF to the main SWF. This method works well if the server hosting the data is under your control. |
Server-side proxy method
The section below includes server side code that will allow you to load data from third domains.
| 1 | Download and unzip or unstuff one (or all of) the following example files:
ColdFusion Example: (1 KB) PHP Example: (1 KB) ASP Example: (1 KB) Java Servlet Example: (2 KB) The above code example must be hosted from a server in the same domain as the Macromedia Flash document. Note: Other server-side scripts can be used. Developers using other types of files can use one of the above examples as guideline. |
| 2 | Replace the URL in the example with the URL that you want Macromedia Flash to load data from. |
| 3 | In the Macromedia Flash movie, in the action that loads the data, point to the URL where you will post the above code example. |
| 4 | Publish and upload both documents. |
Shim SWF method
This section below outlines how the shim SWF method works.
| Goal | |
| ÂÂÂ | Load data from another domain |
| ÂÂÂ | For example, load a variable into Main.swf in yourFlashDomain.com from the file "myData.txt" in yourDataDomain.com. |
| Problem | |
| Because of the security restriction, a call directly to the data source would fail and the data would not be returned. | |
| ÂÂÂ | For example, a loadVariables action in Main.swf pointing directly to myData.txt would not retrieve the variable, because the files are in two different domains (yourFlashDomain.com and yourDataDomain.com). |
| Solution | |
| 1 Create a second "shim" movie, hosted on the same server (or on another server in the same domain) as the data source. 2 The main movie loads the shim movie (for example, into another level) using loadMovie, so both movies are loaded into the Macromedia Flash Player at the same time, on different levels. Example: loadMovieNum("http://www.yourDataDomain.com/somePath/
3 The shim movie contains the actions to load the information into itself from the data source (loadVariables, XML.load, XML.sendAndLoad). Because both documents are in the same domain, the request will be processed. 4 If your shim movie is a version 6 SWF (or later), you must insert additional code to allow the movies to communicate. Insert this code into the shim movie to allow the main movie to access information in the shim movie. Replace yourFlashDomain.com with the domain name of your main movie. Example: System.security.allowDomain("http://yourFlashDomain.com"); Note: Never call System.security.allowDomain unless you fully trust the operator(s) of the domain that you are specifying. By using this code, you are granting access to any movie from that domain. If you do not fully trust the administrator, developers, or documents originating in that domain, the server-side proxy method may be a more appropriate solution. Refer to Additional information for more onSystem.security.allowDomain. 5 When the data reaches the shim movie, reference the information from within the main movie. Examples: mainVar=_level1.shimVar; mainXML=new XML(_level1.shimXML); Note:Use a similar method if you wish to set data in the main movie (version 6 or above) from within ActionScript in the shim movie (any version). IncludeSystem.security.allowDomainin your main movie to grant permission to the shim movie's domain. This would enable you to "push" data to the main movie from the shim movie. This method could be preferable if using a callback function (onLoad, onClipEvent(data)) in the shim movie. In general, the shim method can be used with any combination of versions of SWF files. However, if any one SWF is version 6 (or above) and you need to access it from within a movie hosted in another domain, you must specify the domain inSystem.security.allowDomain(and only if you fully trust the administrator of that domain). |
Additional information
For more information on domain restrictions, refer to External data not accessible outside a Flash movie's domain (TechNote 14213).
For more information on using Flash with a database, refer to Overview of Macromedia Flash and database integration (TechNote 14482).
For more information onSystem.security.allowDomain, refer to the ActionScript Dictionary entry in the updated Macromedia Flash MX Documentation. Refer to Macromedia Flash MX Documentation Update (TechNote 16470) to obtain the update.
This content requires Flash
To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player.
Download the free Flash Player now!
