Exercise 6-3: Deep linking Using SWFAddress - Search Engine Optimization for Flash
by Todd PerkinsThis excerpt is from Search Engine Optimization for Flash. Search Engine Optimization for Flash dispels the myth that Flash-based websites won't show up in a web search by demonstrating exactly what you can do to make your site fully searchable -- no matter how much Flash it contains. You'll learn best practices for using HTML, CSS and JavaScript, as well as SWFObject, for building sites with Flash that will stand tall in search rankings.
Using SWFAddress, you can easily implement deep linking in your site. This exercise gives you practice using SWFAddress with Flex.
-
Open the output file,
index.htmlin thebin-debugfolder for Exercise 6-3 in Flex and notice it links toswfaddress/swfaddress.js. -
In the
srcfolder, open the fileApp.mxml, and then, in Flex, view its code. -
Notice the file’s
<mx:Application>has a value ofinitApp()for itscreationCompleteproperty. -
In the
initApp()function, notice thatSWFAddress’s change event executes thehandleSWFAddress()function. -
Look at the TabNavigator’s
changeproperty. Notice that runs thesetSWFAddress()function. -
Notice the utility and XML loading and displaying functions that are already written.
-
In the
setSWFAddress()function, add the code to update the page’s URL usingSWFAddress’ssetValue()method:SWFAddress.setValue("/" + urls[navigator.selectedIndex] + "/"); -
Remember, the
SWFAddress.setValue()method triggers theSWFAddressEvent.CHANGEevent, which causeshandleSWFAddress()to run. In thehandleSWFAddress()function, write the code to get SWFAddress’ value, remove the forward slashes, set the appropriate selected index of the TabNavigator based on SWFAddress’ value, and then use the formatted version of the value to set the title in the browser window usingSWFAddress.setTitle(). The finished version ofhandleSWFAddress()should look like this:private function handleSWFAddress():void { var value:String = SWFAddress.getValue(); value = value.replace(/\//g, ""); navigator.selectedIndex = urls.indexOf(value); SWFAddress.setTitle(formatAsTitle(value)); } -
Save the file, and then, from the
bin-debugfolder in your web browser, openindex.htmlusing your testing server to view SWFAddress working when you click through the tabs. Nice!
