• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Using FlashVars

Have you ever had a situation where, aside from simple tweaks, a single Flash movie could be used in a number of different ways? For example, imagine having a Flash movie that loads and plays external MP3 files. To use this movie to play 10 different MP3 files would require you to open the original FLA, manually edit a small section of the code that specifies the MP3 to load, and export 10 different SWFs. Or you might have to script the movie to load the information from a database. The first option is too much work and has the potential of turning into a bandwidth nightmare. Even if each SWF contained only a single line that was different, you would still have 10 different SWFs. If each file was 30 KB in size, placing them all on a single page would result in a 300 KB download. The second option, setting up your movie to load data from a database, is generally fine, but might be too complex a solution in some situations. Fortunately, there's a third option that fits nicely in the middle: the FlashVars parameter.

FlashVars, introduced in Flash MX, is an HTML <object> and <embed> parameter/ attribute that provides a quick and easy way to pass data into a movie embedded in an HTML page. Immediately upon loading the movie, the data passed in can tell the movie to do something. This essentially provides a means to configure an SWF via HTML without having to physically open the original FLA and edit its code. In other words, a single SWF can be used for multiple purposes. For example, suppose that a particular SWF plays MP3s. If you embed that SWF in an HTML page, with a few adjustments to the FlashVars parameter in the <object> and <embed> tags you can easily define which MP3 file that particular instance of the SWF should play. The greatest benefit about this functionality is that a single SWF can be repurposed multiple times throughout your entire site, and your visitor only needs to download it once. Your site's overall performance is enhanced.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint