Wednesday, May 23, 2007

Getting a Blogger XML feed to work in Flash

I wrestled for about an hour because the XML from Blogger was coming up blank whenever I ran my project on the web server. This article saved me:

http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=tn_16520

Basically I need to have "proxy.php" in the same directory as the site - with the Atom XML URL inside it. Then, in Flash I need to use "proxy.php" for the path. I think the way this works is that the PHP file reads the XML and stores it, then Flash gets the XML text from the PHP file. This code is in the Nitro Circus project in proxy.php and the "if the planet==3" area of planets.as file.

-------------

Text from Adobe:

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).

1. Download and unzip or unstuff one (or all of) the following example files:
ColdFusion Example:
Windows ZIP
Macintosh SEA

PHP Example:
Windows ZIP
Macintosh SEA

ASP Example:
Windows ZIP
Macintosh SEA

Java Servlet Example:
Windows ZIP
Macintosh SEA

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.

1 comment:

Andrew Paul Simmons said...

Thanks for the help.