Flash CS3 Multiple value array

in this code I am trying to parse a dynamic set of variables into an array.

the data.txt file would look like this.

myArray=one|two|three&num0=hello|hi&num1=hi|hello&num2=goodbye|bye

the data.txt file is dynamic and the amount of num0,num1,num2, etc will be based on how many variables are in the myArray array.

So as you see in the code below, I take the length of myArray and then try to load the num0,num1, etc based on the length count.

I do not get an error with the code below, but I cannot:

trace(numArray0[0]);

it kicks back an error of undefined

Is there a better way of doing this??


var i:Number;
			var holder:String;
			for (i=0; i<myArray.length; i++){
			holder = "num"+i;
			trace (holder);
			this[numArray+i] = urlVars[holder].split("|");

Open in new window

lexshineAsked:
Who is Participating?
 
blue-genieConnect With a Mentor Commented:
hi, sorry been manic with deadlines.
have a look at the code snippet.

i'm just loading a static data.txt file from my harddrive with the variables you specified.
then doing a whole bunch of splits.
then creating the arrays dynamically and storing data.

the showIt function outputs the following

hello,hi
hi,hello
goodbye,bye

var myArray:Array = new Array();
var vars:URLLoader = new URLLoader();
vars.addEventListener(Event.COMPLETE, onComplete, false, 0, true);
 
vars.load(new URLRequest("data/datafile.txt"));
 
function onComplete(evt:Event):void
{
	var myArray:Array = evt.target.data.split("&");
	var numArrayToCreate:Number = myArray.length-1;
 
	for (var i:Number=0; i<numArrayToCreate; i++)
	{
		var counter:Number = i+1;//we only care about the second one onwards.
		this["numArray"+i] = new Array(2);
		//strip out the =
		this["itemToSplit"+i]= myArray[counter].toString().split("=");
		for (var j:Number = 0; j<2; j++)
		{
			this["numArray"+i][j] =  this["itemToSplit"+i][1].split("|");
		}
	}
	showIt();
}
 
function showIt()
{
	trace(this["numArray0"][0]);
	trace(this["numArray1"][0]);
	trace(this["numArray2"][0]);
}

Open in new window

0
 
lexshineAuthor Commented:
a bit more info.

I am forming the datafile.txt from PHP. that is why the composition of the datafile varies and that is why the num0,num1,num2 fields can be dynamic based on the amount of data in myArray.

it is easy to .split in myArray, but each entry in myArray forms a set of data in the num fields and I just have to figure out a way to load those num fields into flash, regardless of how many there are.

hope this clarifies it a bit.
0
 
blue-genieCommented:
how are you actually getting the values into flash?
if you trace myArray.length - do you actually get a value?
remember that when you load the data from the txt file, even if you call it myArray, it doesn't become an array, so you'll need to say something alogn the lines of

var anotherArray:Array = new Array(myArray);
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
lexshineAuthor Commented:
This is how I pull in myArray and yes it does achieve the variables and also have a length value.

I cannot get the dynamic portion of num0 to work tho.


			var vars:URLLoader = new URLLoader();
			vars.dataFormat = URLLoaderDataFormat.VARIABLES;
			vars.addEventListener(Event.COMPLETE, onComplete, false, 0, true);
 
			vars.load(new URLRequest("data/datafile.txt")); 
												
			function onComplete(evt:Event):void {
			var urlVars:URLVariables= evt.target.data;
				
			myArray = urlVars["thearray"].split("|");
 
 
                        }

Open in new window

0
 
blue-genieCommented:
i'm busy trying to replicate your situation.
am i correct in saying ...

from a dynamic value from php e.g.

myArray=one|two|three&num0=hello|hi&num1=hi|hello&num2=goodbye|bye

you want to get the value pairs of num0, num1, num2 etc into arrays.

ie. numArray0  = new Array("hello", "hi");
numArray1 = new Array("hi", "hello");
numArray2 = new Array("goodbye", "bye");

is that the ultimate desired result?

0
 
lexshineAuthor Commented:
yes, that is the ultimate result, with the amount of numArray's being based off of the length of myArray
0
 
lexshineAuthor Commented:
any progress or ideas on this? thanks..
0
 
lexshineAuthor Commented:
maybe I am not implementing the script right but I am getting the error

TypeError: Error #1006: split is not a function.
      at MethodInfo-286()
      at flash.events::EventDispatcher/dispatchEventFunction()
      at flash.events::EventDispatcher/dispatchEvent()
      at flash.net::URLLoader/onComplete()

0
 
blue-genieCommented:
did you just copy and paste?
make sure you have the toString() as you can only apply the split to the string.

i've attached my file with the external data txt file i'm using.


loadData.zip
0
 
lexshineAuthor Commented:
thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.