< Day Day Up > |
We have talked about using text files as a source for application data in a Flash application, but sometimes if the dataset is small, you might want to use basic HTML mechanisms for passing data into an application. There are two simple paradigms that enable us to pass data into the application through the HTML page:
The following subsections discuss each in turn .
FlashVarsUsing FlashVars, we can directly attach the variables as parameters in the object and embed tags in the HTML page. When the application launches in the browser, it reads the param tags attributes set in the object or embed tag. These parameters are used to initialize the application. The parameter FlashVars is used to pass in any number of variables. The format for the data is name -value pairs, the same as the format we saw earlier in LoadVars and loadVariables() . Note that the data must be URL-encoded as well. On startup, the Flash application checks whether the variables exist. If they do, the values passed are assigned to the existing variables. If they don't, new variables with the given name are created and their values set. Listing 11.6 shows the object tag with the FlashVars param tag. Listing 11.6. Object Tag with the FlashVars Param Tag<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/ swflash.cab#version=7,0,0,0" width="385" height="370" id="loanCalc" align="middle"> <param name="movie" value="loanCalc.swf" /> <param name=" flashVars " value="banks=Fleet,Citibank,BankOne&rates=6,5,7" /> <embed src="loanCalc.swf" quality="high" bgcolor="#ffffff" width="385" height="370" name="loanCalc" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /> </object> Listing 11.7 shows how we would use the variables passed in through the object tag. In the application, we will take each set of data and stuff it into an object to be handled by the populateBankList() method. Listing 11.7. Variables Passed to a Flash Application from FlashVarsvar banks:Array; populated by FlashVars at startup var rates:Array; populated by FlashVars at startup var ratesObject:Object = new Object(); ratesObject.banks = banks; ratesObject.rates = rates; populateBankList(ratesObject); FlashVar string sizes of up to 64KB (65535 bytes) in length are supported by all browsers. Query StringThe variable information can also be passed to the main timeline of the Flash application passed in through the query string. In Listing 11.8, we have modified the object tag so that the variable data is appended to the SWF name. The application will behave the same as if we were using FlashVars. Listing 11.8. Variables Passed to a Flash Application from a Query String<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/ swflash.cab#version=7,0,0,0"" width="385" height="370" id="loanCalc" align="middle"> <param name="movie" value="loanCalc.swf?banks=Fleet,Citibank,BankOne&rates=6,5,7"/> <embed src= " loanCalc.swf?banks=Fleet,Citibank,BankOne&rates=6,5,7 " quality="high" bgcolor="#ffffff" width="385" height="370" name="loanCalc" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /> </object>
|
< Day Day Up > |