Okay, not sure if this the right place to put this, but I just wanted to share my discoveries, because I think others will find it incredibly useful. Taken originally from my blog at http://www.anthonycargile.com/blog/?p=36 :
Here’s what I needed this for: a client of mine is having me do a flash site, and as we all know flash is a one time deal, make the swf, embed it, and updates mean recompiling the swf. Now some get fancy and pass parameters to the movie via the corresponding HTML tag, but that could possibly lead to security vulnerabilities. Flash DOES, however, support reading external xml files over the network, allowing you to update an app just by re-uploading a new xml file, but for me, no, even that was not good enough.
This client of mine is a model. She gives me an average of 10 new pics a week to put on the (soon-to-be-old-yet-kept-for-accessibility-while-keeping-the-same-content-as-the-flash) site, which as mentioned above is a problem for flash. Enter using xml, which saves me from recompiling the whole shebang, but for an average 10 photos a week, I’m sorry but that is just waaay to much work for a programmer of my caliber.
Now the old html-php site used a custom portfolio I made that actually per-request went into the image directory, fetched the photos out of the subdirectories that were the same name as the album (which were specified in the query string after stripping any hackers’ slashes), then placed them in a javascript-paged image viewer. All I had to do to update it was add the new pics to the correct album name directory, and the next page requests would automatically put them there.
So how do we do this same thing in flash? Well, flash was smarter than to to read an “xml” file with a .php extension, apparently hard-coded in there by adobe. So, since I favor Linux web hosting under apache, I made a little .htaccess file, and added:
in there. Now, I only did this because I am 100% sure that I won’t be needing anything else xml-related that would disagree with php for this website, otherwise I would put it in a directory, although I have not tested this.Code:AddType application/x-httpd-php .xml
What this does now, is let the webserver’s php processor execute any php code in any .xml file prior to serving it. I am lucky that flash is so client side that it actually REQUESTS the .xml file rather than open it (in a fopen() flashion) and then read the contents, which would just give the app php code, obviously not the desired effect here.
So now that php can process a .xml file before handing the output to flash upon request, I can just tell php to add a new xml tag for each image found in the album directories, which includes an image URL that flash can load into the app for viewing pleasure.
Not exactly 100% creative, but still, a nice way to incorporate laziness into a flash app. As subtly mentioned above, for non-javascript/flash enabled users, the old (lynx/screenreader capable) html website will still be kept around, and it uses the same server-side technique for content management, so both the flash and html sections of the site will display the same content that I simply had to add to a directory.





. And as far as security as mentioned above, I'm only using the AddType for the flash directory, which stores the xml files, and getting FTP access to the server is quite hard, again thanks to my hosting provider whom changes the port that sftp listens one.
.

Bookmarks