LoadVars class

Availability:

SmartFoxServer PRO 1.4.2

Description:

The LoadVars object allows to load text data from a remote HTTP server, in the format of a query string.
It's usage is identical to the LoadVars object in Flash.

Public Methods:

send(url, method)   Send data to a url using the specified http method (get, post)
url - a valid http url
method - "get" or "post"
load(url)   Loads data from a valid http url
sendAndLoad(url, target, method)   Send data to a url and load the result coming from the server.
url - a valid http url
target - a LoadVars object that will receive the response
method - "get" or "post"
onLoad(success, errorMsg)   This method is invoked asynchronally when the data has been retrieved.
success - is true, if the variables were loaded
errorMsg - tells you which error occurred, if any

Example of usage:

/*
* SmartFoxServer PRO
* Test LoadVars
* v 1.1.0
*/

function init()
{
   var _send = new LoadVars()
   var _load = new LoadVars()
   
   // Set parameters to send
   _send.name       = "Albert"
   _send.surname    = "Einstein"
   _send.job       = "genius"
   _send.location    = "Germany"
   
   // Handle the remote data
   _load.onLoad = function(success, errorMsg)
   {
      if (success)
      {
         trace("Data received:")
         
         trace("Name    : " + this.name)
         trace("Surname : " + this.surname)
         trace("Job     : " + this.job)
         trace("Location: " + this.location)
      }
      else
      {
         trace("Loadvar Failed. " + errorMsg)
      }
   }
   
   // Send data with POST method and receive it back in the _load object
   _send.sendAndLoad("http://www.smartfoxserver.com/temp/loadvars.php", _load, "post")
}


function destroy()
{
   trace("Bye bye!")
}


function handleRequest(cmd, params, user, fromRoom)
{
   //
}


function handleInternalEvent(evt)
{
   //
}