Article

Accessible Flash Parts 1 And 2

Page: 1 2 3 4 5 6 Next

Making PHP talk to Flash

That's it for the PHP scripting: three simple inclusions, and one that contains script that will combine everything together.

The code has successfully supplied a known searchbot with text content from the database table, and stopped it from indexing the Flash html code. The searchbot will now send back to its parent search engine the text and hyperlinks it finds, and the link to this content will soon appear in the search engine listings.

The second part of this process involves what happens when one of the hyperlinks that's found in a search engine listing is activated by one of us, or when the URL is typed directly into the browser -- i.e. when $bot is not set. In this case, the PHP interpreter skips entirely the supplying of text content in filtering.inc.php, and moves on to the code that displays the Flash movie.

The PHP script now needs to pass the valid request to Flash, accomplished by adding the $go variable to the Flash movie filename. What this does is very simple yet powerful -- it will pass the value of $go into the movie, making it available to ActionScript as the variable _root.go.

This is the linkage between the URL and the Flash movie and, most importantly, makes the whole process possible.

The ActionScript Starts

Once my Flash Website loads up, I can retrieve content from the database based on the value of _root.go, knowing that it has been validated by the previous PHP script. This will be the same content retrieved by a search engine using $go as the identifier.

There are many ways to retrieve dynamic content for Flash. One method uses LoadVars, a Flash Player 6-based object that can talk to a server side script like PHP. It won't work with older versions of the Flash Player (lower than 6), so if your target Player is version 3 to 5 you should use the loadVariables function.

_root.go will be available to the Flash movie from frame 1, so it can instantly be added to a LoadVars object:

contentFetcher = new LoadVars();    
contentFetcher.id = _root.go;    
contentFetcher.sendAndLoad("requestcontent.php",    
contentDisplay, POST);

Here I transfer _root.go into a new LoadVars object called contentFetcher, then send the object content(s) to a PHP script called requestcontent.php. This PHP script retrieves content from the database table and prepares it for Flash in url-encoded format. Once the script is run successfully, the results are retrieved for display in the movie using an onLoad event handler.

Achieving the Target

My initial target of getting the search engines to index my Website was achieved! I soon found my Website in Google's cache. There was my listing, with all the content from my database indexed and no Flash visible at all. Paradoxically for a Flash developer, this is what I wanted!

The beauty of this system can be seen in

  • Simplicity: three basic scripts do all the work
  • Scalability: the virtue of having the content for search engines update automatically whenever the 'human readable' content is updated
  • Transparency: for both types of site visitors, bot and human, the other's content is rendered invisible with some simple scripting
  • Platform Independence: the scripts run on the server, so there are no problems with non-compliant browsers mangling the code

As with most things in life, achieving something worthwhile tends to have positive run-on effects. In this case, my tinkering with passing variables to Flash from the URL partly solved an accessibility bug that acted as a barrier for many who considered building Flash Websites -- bookmarking.

For the second part of this case study I'll belt out some code on how bookmarking can be achieved. We'll look at some alternate methods you can use if you don't have a database, outline some advantages and disadvantages of the system, along with possible future directions, and discuss a quick warning regarding cloaking.

And a note - you can download the code for both articles right here!

If you liked this article, share the love:
Print-Friendly Version Suggest an Article

Sponsored Links