Flash man by Zerofractal Studio
7/22/09 UPDATE: Read the latest tips, and download more simplified and updated files HERE.
Back in October I wrote a tutorial on how to utilizing deep links in Flash files. This post has consistently been the most viewed page on the site and I have been receiving several emails asking for help fixing bugs. Although I am happy to help individual cases, I decided it might be best to provide my files as well as publish other II reader’s trials, tribulations and success stories to help everyone out there who is also working with SWF Address.
Here is my example, where I built the very basic core functionality of a Flash file using AS2 with deep links. Notice how the forward and back button on the browser works to navigate through the site.
(You aren’t judging the lack of design, right?? … hey, I am a student so I have to balance my time!)
Click here to download these files. Included you will find eight files:
swf_address.fla (CS3)
swf_address.swf
index.html
AC_RunActiveContent.js
SWFAddress.as
SWFAddressEvent.as
swfaddress folder with two files:
swfaddress.html
swfaddress.js
I suggest that you begin by opening my file, adding buttons and the corresponding code to make it work on your own. Then, start with a fresh .fla in the same directory, using all of the other javascript files, and try to make that work. Once you get the basic functionality working, then try to integrate it into a larger project with other code. This way you will know whether or not pre-existing code is preventing your deep links from working correctly.
Here are case examples from II readers who have used it in their projects:
Pieter Brink successfully integrated it into his African production company website. He got it working from my initial tutorial, so congrats to him!
Camilo Cadena is incorporating deeplinking into a small business site. Currently, this version has a bug in IE 6 and 7 that aborts the script and begins looping if the user repeatedly hits the back button. I am assuming it is because the file is so large that it takes a second for the deep link to update, and this delay breaks the code. While he works out this last bug, here are his tips for getting as far as he did:
Reader Julianne Veterre is also currently on the verge of getting it to work. Since she is using CS4 (lucky her) I cannot see her files, but here is her situation in case others have done through something similar and figured it out:
“I have the pages and the links changing. However my loader quit working, and when you hit the back button, in FF, the link changes but the page stays the same…and in IE hitting the back button takes you all the way back out of the page.”
So, for all you programmers out there, if you can help Camilo and/or Julianne, please leave suggestions in the comments! For everyone else, I hope my example files help you accomplish deep linking for your future projects.
Happy coding II readers!
SWFaddress works well, perhaps too well. If you only need to read and change a URL, then look into the following functions:
function getUrl():String {
var sUrl = flash.external.ExternalInterface.call (“function ( ) { return window.location.href; }”);
var sNum:String = sUrl.substr(sUrl.lastIndexOf(“#”) + 1);
return sNum;
}
function setUrl(s:String):Void {
var sUrl = flash.external.ExternalInterface.call (“function ( ) { return window.location.href; }”);
var sNum:String = sUrl.substr(sUrl.lastIndexOf(“#”) + 1);
sUrl = sUrl.substr(0, sNum)
var newUrl:String = sUrl + “#” + s;
var jsFunc:String = “function ( ) { window.location.href=\”" + newUrl + “\”; }”;
flash.external.ExternalInterface.call (jsFunc);
}
—
A bit of tweaking and you’re there.
Thanks, Eirik! I will look into your code and try it on my example files. I am assuming that you still need the .js and .as files with the js call in the html file?
How do you suggest handling Query Params? I added a test param to your base URL and then after clicking around the swf address gets concatenated to the end.
This may be the clearest description on using swfAddress with AS2, I have read yet! Thanks so much. I’ll let you know how it goes!