Flash
  Home arrow Flash arrow Page 2 - The Power of LoadVars Object
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
FLASH

The Power of LoadVars Object
By: Adi Reddy Mora
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 28
    2005-02-09

    Table of Contents:
  • The Power of LoadVars Object
  • Advantages of the LoadVars class
  • Receiving the variables in server-side script
  • Using LoadVars Object for loading data from text files
  • LoadVars.decode

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    The Power of LoadVars Object - Advantages of the LoadVars class


    (Page 2 of 5 )

    The advantages of the LoadVars class include the following:

    • You don't need to create container movie clips for holding data or clutter existing movie clips with variables specific to client/server communication.

    • The class interface is similar to the XML object, which provides some consistency in ActionScript. It uses the methods load(), send(), and sendAndLoad() to initiate communication with a server. The main difference between the LoadVars and XML classes is that the LoadVars data is a property of the LoadVars object, rather than an XML Document Object Model (DOM) tree stored in the XML object.

    • The class interface is more straightforward—with methods named load, send, sendAndLoad—than the older loadVariables interface.

    • You can get additional information about the communication, using the getBytesLoaded and getBytesTotal methods.

    • You can get progress information about the download of your data.

    • The callback interface is through ActionScript methods ( onLoad) instead of the obsolete, deprecated onClipEvent (data) approach is required for loadVariables.

    • There are error notifications.

    • You can add custom HTTP request headers.

    The following are the five basic steps involved in using LoadVars Object for communicating with any server:

    1. Instantiate two LoadVars objects, one for sending variables from flash and one to receive any variables that are sent from the server.

    2. Define and associate the flash variables to LoadVars object that are required to send to the server.

    3. Use sendAndLoad method to send the associated variables to the server as POST/Get variables and also specify the LoadVars object for receiving variables from the server.

    4. Use onLoad event handler method to assign a function which fires when the variables are received from the server. The onLoad handler is passed a true or false Boolean value indicating whether the data was submitted successfully.

    5. Create a function with the name specified in step 4 to handle the received variables. The function will be called when the server's reply has been received. You need to write this function yourself.

    Let us see an example now to demonstrate the above steps in ActionScript 2.0

    Step 1

    var reply_lv = new LoadVars();

    var send_lv = new LoadVars();

    Step 2

    send_lv.type = "BUTTON";

    send_lv.id = "1";

    Step 3

    send_lv.sendAndLoad("asp_net_php_page", reply_lv, "POST");

    Step 4

    reply_lv.onLoad = loadedDotNetVars;

    Step 5

    function loadedDotNetVars(success){

        if(success) {

              // operation was a success

              trace(reply_lv.name)

        }

        else {

              // operation failed

        }
    }

    If the sendAndLoad operation finishes without errors, any variables returned by the server will be placed into reply_lv and the loadedDotNet function will be invoked.

    Note: "name" is the variable name that was specified in the server-side script.

    If the http send method was set to GET, all the variables will be sent to the server in query string format like:

     

    type=BUTTON&id=1

    Suppose you are sending arrays to the server, and those array values are sent as a comma-delimited list. For example, if you are sending the following data:

    send_lv.type = "BUTTON";

    send_lv.id = "1";

    send_lv.colors = [ "red", "white", "blue" ];

    Then the query string will look like this:

    type= BUTTON&id=1&colors=red,white,blue

     

    More Flash Articles
    More By Adi Reddy Mora


       · I am Adi Reddy Mora, the author of this article from India. This is my 1st article...
       · Hi, I am a newbie in Flash. I am interested on your topic here. I have a problem on...
       · Flash does not deal with the proxy settings. If you are able to connect through...
     

    FLASH ARTICLES

    - Decorator Pattern
    - Organizing Frames and Layers for Flash Anima...
    - Organizing Frames and Layers
    - Using XML and ActionScript with Flex Applica...
    - Interfaces and Events with ActionScript and ...
    - Manipulating Data with ActionScript in Flex ...
    - ActionScript Syntax for Flex Applications
    - ActionScript in Flex Applications
    - A Closer Look at Apollo`s File System API
    - Using the File System API
    - ActionScript 101
    - Flash Buttons
    - Advanced Flash Animation
    - Creating Your First Animated Movie with Flas...
    - Flash: Building Blocks






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
    Stay green...Green IT