15.6. Loading Remote Content by Proxy

Problem

You want to load content into your Flash movie from another domain and are prevented from doing so by Flash’s security sandbox.

Solution

Use a proxy script on the server to overcome the domain restrictions.

Discussion

Flash’s security sandbox prevents you from loading content into your Flash movies from other domains indiscriminately. You can load .swf files, JPEGs, and MP3s from the same domain (or subdomain), and you can also load .swf files from a trusting domain. However, if you need to load content that is not in the same domain, and it is not a trusted .swf file, you have at least three options:

  • Copy the content to the same domain. This is the simplest solution if it is possible for you to implement.

  • Create a DNS entry within your own domain such that the remote server is mapped to a machine name within the same domain. For example, you can create a DNS entry such that www.remotedomain.com maps to remotedomain.localdomain.com within your own domain. This solution requires that you have administrator access and DNS knowledge.

  • Create and use a proxy script that downloads the remote content to the local server (either in memory or to disk) on the fly and then returns the local copy to the Flash movie.

Included in this recipe are instructions for creating proxy scripts for ColdFusion, Perl, .NET, and PHP.

If you use ColdFusion, you can write a proxy script with just a few lines of code. Be aware that for this to work, the <cfcontent> tag ...

Get Actionscript Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.