Welcome To VertexTemplates.com Flash MX 2004 Tutorials Area - Passing variables to flash |
![]() |
|||
Flash MX 2004 Passing variables to flash Tutorial.
Author: vecpix.com As part of my site deign I was after a method in which I could have a reusable banner. This banner was going to be a flash program and would be cached for every page. I wanted to pass a variable to the flash program, and that would be the title for that page. There are several methods of passing variables to a flash program. The first method that I used, passed the variables via the HTML tag value. Below is an extract of the code that I use for the navigation bar: <OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" The code in yellow is what I added to get the variable passed to my flash program. Inside my flash program I use the variable "first_menu" to indicate which menu has to be displayed when the page is loaded. This works well, but for one problem. Passing a variable in this manner causes the browser to cache each variation of the variable. In the above example, I would have a "nav_bar_mncom.swf?first_menu=Web%20Design" variable in my cache. For the navigation bar there are only a few variations so it was not a problem. But with the banner, every page had a different banner, and therefore the browser ended caching every variation. This partly defeated the purpose of having a reusable banner. So another method was needed which kept the same swf in cache. The method used was the Javascript setVariable method. <script language = "JavaScript"> <body onLoad="PassFlash()" > <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" Extra bits have to be added in the code that loads the swf plugin. They are the id=mndbanner in the codebase tag, the NAME=mndbanner and swLiveConnect=true in the embed tag. The movie name ( name of the swf file), in this case mndbanner has to be the same as shown. One final piece of code that has to be included is the onLoad="PassFlash()" inside the body tag. This tells the browser to execute the javascript function PassFlash() when the page is loaded. Keep in mind that the variable will not be passed till the page is fully loaded. Another option to load the banner variable is to included a call of the PassFlash() function just after the object is defined. <script language = "JavaScript"> <body> <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" |
||||
| Home Web Templates Affiliate Program Template Tour Custom Website Design Tutorials Articles Contact Us FAQ's All Rights Reserved © 2005 VertexTemplates.com Read our Terms Of Use and Privacy Policy Flash Templates by Metamorphosis Design |
||||