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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

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
blue-genieCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.