Posted
Filed under Action Script

[원문]  - http://theolagendijk.wordpress.com/2007/07/06/parameters-for-a-flash-9-actionscript-3-swf/

Recently I wrote a blog post about the differences between ActionScript 3.0 and ActionScript 2.0. One major difference that I found and dealt with had been lost in my unordered notes of what I wanted to write about;

Passing parameters to Flash.
Why would you want to that? Consider the case that your website consists of one giant swf file (and there are valuable reasons to have such a website). Off course the swf will probably be embedded inside a HTML page that links the swf content to some meta data and offers some alternative HTML content for the visitor that have no Flash plugin for their browser, but the content that you want to show to the visitor is all trapped inside that swf file. If for example you had blog content inside that swf, it would kind of suck that you have no means for giving friends URLs to directly jump to a specific blog post inside that swf similar to what you achieve with permalinks in HTML blogs. (I can for example give people the hyperlinks to blogging-in-flash or findability-and-linkability-with-flash to directly point them to what I want them to read about.) And this is just one example of why you would want a way of “indexing your swf”/”generate your swf based on parameters”.

So here it is then. A short explanation of implementing parameter passing to an ActionScript 3.0 swf. It still is as simple as having your browser request the swf file with extra parameters folowing the name of the file. Like this; name_of_your.swf?param1=value1&param2=value2&param3=value3 etc… this part hasn’t changed. But getting access to the passed parameters has. In ActionScript 2 you used to have global access to the parameters as they where added as variables to the _root namespace. Now it’s slightly different, they’re now stored in the loaderInfo of the Stage object. (So it’s only accessible from the Stage object itself or members of it’s display tree.
Here’s example code reading the variables;

var keyStr:String;
var valueStr:String;
var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters;
for (keyStr in paramObj) {
valueStr = String(paramObj[keyStr]);
//do something with this information
}

Something else
There’s something else that slightly touches this subject. Use the Adobe Flash Player version detection kit. The flash 9 player is taken over the old players but not everyone is having the new player yet. Be sure to detect this and gently notify your visitors of the need to update their Flash plugin. That’s so much better then seeing nothing or an incorrectly functioning website! The kit provides of examples of it’s use but it might confuse you of where to insert the Flash parameters into the JavaScript function call that generates the embedded Flash object. Just add the parameters in the src string tuple (’src’, ‘your_swf_location‘), you can omit the .swf file extension here.

For example this is the javascript (generated from a server side script) function call that embeds the Studio Roosegaarde 2.0 swf with parameter blog_item(=15);

if(hasRightVersion) { // if we’ve detected an acceptable version
// embed the flash movie
AC_FL_RunContent(
‘width’, ‘100%’,
‘height’, ‘100%’,
src‘, ‘StudioRoosegaarde2?blog_item=15‘,
‘quality’, ‘best’,
‘pluginspage’, ‘http://www.macromedia.com/go/getflashplayer’,
‘name’, ‘StudioRoosegaarde2′,
‘allowScriptAccess’,’sameDomain’,
‘allowFullScreen’,'true’
); //end AC code
}

2010/03/15 16:19 2010/03/15 16:19