[u][b]Introduction:[/b][/u]
[b]FlashVars[/b] is a property of Adobe Flash Player to import variables into the top level of movie when first instantiated. This is useful to make a dynamic swf movie content.
This tutorial is useful to your profile if you are using flash and if you want to make its content dynamic.
[u][b]Requirements:[/b][/u]
1. Adobe Flash CS3
2. Some basic knowledge about Actionscript 2.0
[b][u]Step 1:[/u][/b]
Open your Adobe Flash CS3 and create a new Flash file.
Setup the size of the stage in any size you want.
[img]http://i173.photobucket.com/albums/w76/myparis16/p1.jpg[/img]
[u][b]Step 2:[/b][/u]
Create a new text field in your stage.
Drag the Text Tool in the stage and set its size.
[img]http://i173.photobucket.com/albums/w76/myparis16/p2.jpg[/img]
Click on the newly created text field,on the [b]Properties Panel[/b] Select the [b]Dynamic Text[/b] and give it an instance name of [b]text1[/b]
[img]http://i173.photobucket.com/albums/w76/myparis16/p3.jpg[/img]
[u][b]Step 3:[/b][/u]
Put some Actionscript.
Click the first frame of the movie
[img]http://i173.photobucket.com/albums/w76/myparis16/p4.jpg[/img]
and press F9 to show the Actions Panel.
[img]http://i173.photobucket.com/albums/w76/myparis16/p5.jpg[/img]
type in this codes:
[img]http://i173.photobucket.com/albums/w76/myparis16/p6.jpg[/img]
EXPLANATION:
-The first line
[quote][color=blue]stop[/color]();[/quote]
commands the movie from stop playing, because i will not make the movie loop even though its just 1 frame.
-In the second line
[quote][color=blue]var[/color] varString1;[/quote]
declaring a new variable named varString1. This variable will hold any string to be past from outer to inner swf movie.
-The last line
[quote][color=blue]_root[/color].text1.text = [color=blue]_root[/color].varString1;[/quote]
[color=blue]_root[/color] code determines that the object or variable is located at the root frame of the movie. Here we set the content of the Text Field object [b]text1[/b] to the content of the variable [b]varString1[/b].
Now Test your movie (ctrl + enter). The ouput should be like this:
[img]http://i173.photobucket.com/albums/w76/myparis16/p7.jpg[/img]
The text said [i]undefined[/i] because the variable varString1 still contains nothing.
Save your work.
[b][u]Step 4:[/u][/b]
In the publish settings (Ctrl+Shift+F12) choose the formats.
[img]http://i173.photobucket.com/albums/w76/myparis16/p8.jpg[/img]
Click [b]Publish[/b].
It will now generate a html code like this:
[quote]<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="400" height="100" id="tuts" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="allowFullScreen" value="false" />
<param name="movie" value="tuts.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><embed src="tuts.swf" quality="high" bgcolor="#ffffff" width="400" height="100" name="tuts" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>[/quote]
Now add the [b]FlashVars[/b] property.
in the <object> tag add a <param> tag like this
[quote]<param name="[b]FlashVars[/b]" value="[b]varString1[/b]=[color=red]HelloWorld[/color]">[/quote]
and in the <embed> tag add a new attribute [b]FlashVars[/b] like this:
[quote]<embed [b]FlashVars[/b]="[b]varString1[/b]=[color=red]HelloWorld[/color]" />[/quote]
The Final code should look like this after adding the [b]FlashVars[/b] Property
[quote]<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="400" height="100" id="tuts" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="allowFullScreen" value="false" />
<param name="movie" value="tuts.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<param name="[b]FlashVars[/b]" value="[b]varString1[/b]=[color=red]HelloWorld[/color]">
<embed src="tuts.swf" [b]FlashVars[/b]="[b]varString1[/b]=[color=red]HelloWorld[/color]" quality="high" bgcolor="#ffffff" width="400" height="100" name="tuts" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>[/quote]
Now test your work. If you run the swf movie in the browser the output should be like this:
[img]http://i173.photobucket.com/albums/w76/myparis16/p9.jpg[/img]
If you want to merge it on a Js File and if you want to pass an variable from a Js File just [b]concatenate[/b] the Js variable in the code, like this:
[quote]var swf_kow = "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0\" width=\"400\" height=\"100\" id=\"tuts\" align=\"middle\">
<param name=\"allowScriptAccess\" value=\"sameDomain\" />
<param name=\"allowFullScreen\" value=\"false\" />
<param name=\"movie\" value=\"tuts.swf\" />
<param name=\"quality\" value=\"high\" />
<param name=\"bgcolor\" value=\"#ffffff\" />
<param name=\"[b]FlashVars[/b]\" value=\"[b]varString1[/b]="+[color=red]pageViewerFName[/color]+"\">
<embed src=\"tuts.swf\" [b]FlashVars[/b]=\"[b]varString1[/b]="+[color=red]pageViewerFName[/color]+"\" quality=\"high\" bgcolor=\"#ffffff\" width=\"400\" height=\"100\" name=\"tuts\" align=\"middle\" allowScriptAccess=\"sameDomain\" allowFullScreen=\"false\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />
</object>";[/quote]
If you use more than 1 variable and want to pass more values, make it like this:
in the <object> tag
[quote]<param name="[b]FlashVars[/b]" value="[b]varString1[/b]=[color=red]HelloWorld[/color][b]&[/b][b]varString2[/b]=[color=red]HelloToo[/color]">[/quote]
and in the <embed> tag
[quote]<embed [b]FlashVars[/b]="[b]varString1[/b]=[color=red]HelloWorld[/color][b]&[/b][b]varString2[/b]=[color=red]HelloToo[/color]" />[/quote]
use the [b]&[/b] to separate different variables
Thats it.
sample preview: [url=http://profiles.friendster.com/myparis]http://profiles.friendster.com/myparis[/url]
Just look in my banner or in the comments area it looks like this
[img]http://i173.photobucket.com/albums/w76/myparis16/p10.jpg[/img]
correct me if something wrong here...
hope it helps..
Last edited by myparis (2008-03-17 09:56:19)