Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / Flash / Data Integration / March 2005



Tip: Looking for answers? Try searching our database.

Loading an array from an external file

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
SimonTheSwift - 30 Mar 2005 23:28 GMT
It's about "asymmetry" in LoadVars(). I want to load an array, but didn't know
how to actually story it in the external file. So I used LoadVars.toString() to
show me the format and when I used it, it doesn't work. I guess I am missing
some step. I am attaching the code.

/* Asymmetry in LoadVars() */

/* Idea: I want to load an external variable, in this case an
   array, from an external file (data.txt), using LoadVars().
   
    The question is how to store an array in the external file?
   
    I use the LoadVars.toString() method to see how LoadVars()
    stores an ActionScript array */

// First, I create the array
var myArray1:Array = new Array("cat","dog","pig");

// Then I create the variable using LoadVars()
var myVars1:LoadVars = new LoadVars();
myVars1.collection = myArray1;

// Then I use LoadVars.toString() to see how to store it
trace(myVars1.toString());
// The output is
// collection=cat%2Cdog%2Cpig

/* Logically, if I store the above output into data.txt and
   use LoadVars() to load the array variable into an ActionScript
    array, it should work. */

var myVars2:LoadVars = new LoadVars();
var myArray2:Array = new Array();
myVars2.onLoad = function(ok) {
    if(ok) {
        myArray2 = myVars2.collection;
    }
}
myVars2.load("data.txt");
trace(myArray2);
// There is no output

/* When checking the Debug->List Variables, this is what gets stored
   in myArray2:
   
       Variable _level0.myArray2 = "cat,dog,pig\r\n"
   
    If one uses trace(myArray2), there is no output...
   
====================================================================

   The question is, why isn't this process symmetric? I asked the
    method itself to show me how to store an array, and when I use
    that format, it does not load it */
SimonTheSwift - 31 Mar 2005 00:30 GMT
Ok, I was working more on the problem of loading an array from an external file
using LoadVars(), and found a different solution:

Let's say that the external file contains the following

     collection=cat,dog,pig

When using LoadVars(), Flash loads it as this (using Debug->Variables List)

     collection:"cat,dog,pig"

Which is a String. So, it is possible to use the following code

     myArray = myVars.collection.toString().split(",");

to change String into Array.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.