problem:
how to inform an swf with some arguments / parameters with values
solution:
Passing arguments from URL query (http://www.mycompany.com....)
http://www.mycompany.com/movie.swf?firstVar=101ps
Passing arguments from HTML code
Assuming the image filename is image1.jpg, located at a folder named images. And assuming that the Flash movie will use a variable named imageFilename to refer to the file, then we can do this:
<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://download.macromedia.com/"
WIDTH="250" HEIGHT="300" id="flaMovie1">
<PARAM NAME=movie VALUE="flaMovie1.swf?imageFilename=images%2Fimage1%2Ejpg">
<PARAM NAME=quality VALUE=high>
<PARAM NAME=bgcolor VALUE=#FFFFFF>
<EMBED src="flaMovie1.swf?imageFilename=images%2Fimage1%2Ejpg"
quality=high bgcolor=#FFFFFF WIDTH="250" HEIGHT="250" NAME="flaMovie1"
TYPE="application/x-shockwave-flash"
PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">
</EMBED>
</OBJECT>
There you see that I appended a query string after the Flash movie filename (flaMovie1.swf). The query string contains one variable: imageFilename, with the value of images/image1.jpg.
Note: The %2F is the url encoding for the "/" sign, and %2E is the url encoding for the "." sign. Since these symbols are unsafe or reserved, we should url encode them, although at the present Flash does not seem to care. So saying: imageFilename=images%2Fimage1%2Ejpg is essentially the same as saying imageFilename=images/image1.jpg. (see: Introduction to URL Encoding)
Reading arguments in Flex from HTML
root.loaderInfo.parameters.firstVar
root.loaderInfo.parameters.ImageFilename
The "parameters" is an array with the arguments. The "firstVar" in Flex code is not a known variable but it is supported from Array or Flex.
No comments:
Post a Comment