The loadVariablesNum() Method


The loadVariablesNum() Method

The loadVariablesNum() method is similar to the loadVariables() method in that it loads external variables into Flash, but unlike the loadVariables() method, the loadVariablesNum() method loads the variables into a level instead of directly into a movie clip.

The basic layout of this method looks like this:

 loadVariablesNum(URL, level, method); 

Following are the parameters that loadVariablesNum will accept:

  • URL The path to either the text file being loaded or the middleware page being called.

  • level The level in the Flash player to receive the variables when they are loaded.

  • method This is an optional parameter used to define the method used when transferring data to and from middleware.

It also supports the onData event as a means of announcing when data has been fully loaded.

Here is an example using the loadVariablesNum() method:

1.

Create a new Flash document.

2.

Save this document as sample-20-4.fla in the same directory as the text files you have been working with.

3.

In the first frame on the main timeline, open the Actions panel and place these actions in it:

 //get the data from the text file loadVariablesNum("sample.txt",0); //when the movie receives the data this.onData = function(){      if(init){           trace("my name is - "+this.name);           trace("my age is - "+this.age);           trace("my location is - "+this.location);      }else{           init=true;      } } 

Notice that this time, we use a conditional statement to make sure that the event is not accidentally being triggered by the main timeline's initialization. Also notice that we are calling the original text file we created, not the one we used to put in an array.

Now test the movie, and you will see in the Output panel the same text that was in Figure 20.4.

But the two methods we have covered in regard to loading external data are not the end. There is even a built-in object specifically designed for interfacing with external data.




Macromedia Flash Professional 8 Unleashed
Macromedia Flash Professional 8 Unleashed
ISBN: 0672327619
EAN: 2147483647
Year: 2005
Pages: 319

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net