Categories

Partners
  • Website Templates

  • Design Feeds

  • Adobe Photoshop Tutorials

  • Website Templates, WordPress Themes

  • Website Templates

  • Flash Web Sites

  • Photoshop Templates

  • Photo Contests

  • Photo Tips
  • Search


    Advanced Search


    Partner Links
  • Adobe Photoshop Tutorials

  • Free Stock Photos and Images



  • Website Templates

    Using the LoadVars Class to Load Variables
    Published  06/19/2006 | Macromedia Flash
       




    Using the LoadVars Class to Load Variables

    The LoadVars class has three different methods: LoadVars.load, LoadVars.send and LoadVars.sendAndLoad. Basically, the load method loads variables from an external file or script, while the send method sends Flash variables to a remote script. The final method, sendAndLoad, is a combination of the first two methods. It sends variables from Flash to a server-side script and then waits for a response. This can be very useful if you need to send a user's information to a script and then display a message depending on if the information was valid or not. For example, you may have built a simple login form where the user types in their username and password to gain access t o your site. If the username and password matched values in the database, you could do a gotoAndPlay("welcome") to let them enter the site. If the username and password didn't match, you may want to display a message prompting them to try again, or else click on the register link to sign up for an account. Likewise, if you were building a game, you may want to send the user's score to a server-side script wherich would insert the score into a table. If the user ranked within the top 20 scores you could forward them to a congratulations page.

    You can see a brief example of the load method below, along with an event handler for the onLoad event, which gets triggered after the data has finished loading.

    1. var myLoadVars_lv:LoadVars = new LoadVars();
    2. myLoadVars_lv.load("params.txt", myLoadVars_lv);
    3. myLoadVars_lv.onLoad = function(success:Boolean) {
    4.     if (success) {
    5.         trace("myLoadVars_lv loaded:");
    6.         for (i in myLoadVars_lv) {
    7.             trace(" myLoadVars_lv."+i+" = "+myLoadVars_lv[i]);
    8.         }
    9.     }
    10. };
    Article Series
    This article is part 12 of a 13 part series. Other articles in this series are shown below:
    1. Flash FAQ - Introduction
    2. Streaming FLV files in Flash MX 2004
    3. Creating an XML Packet with Flash - the easy way
    4. Creating an XML Packet with Flash - the hard way
    5. Getting more colors for your Halo
    6. Loading in Images Using the MovieClipLoader Class
    7. Parsing an XML Packet in Flash
    8. Parsing XML in Flash Using the XMLConnector
    9. Sending an XML Packet to a Server-Side Page
    10. Using LoadVars.send Method to Exchange Data with a Server-Side Script
    11. Using the Alert component
    12. Using the LoadVars Class to Load Variables
    13. Using XPath in Flash MX 2004