?
Solved

Flash CS3 Multiple value array

Posted on 2008-11-06
10
Medium Priority
?
232 Views
Last Modified: 2013-11-11
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

0
Comment
Question by:lexshine
  • 6
  • 4
10 Comments
 

Author Comment

by:lexshine
ID: 22911093
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
 
LVL 39

Expert Comment

by:blue-genie
ID: 22922319
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
 

Author Comment

by:lexshine
ID: 22946574
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 39

Expert Comment

by:blue-genie
ID: 22948155
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
 

Author Comment

by:lexshine
ID: 22952116
yes, that is the ultimate result, with the amount of numArray's being based off of the length of myArray
0
 

Author Comment

by:lexshine
ID: 22978337
any progress or ideas on this? thanks..
0
 
LVL 39

Accepted Solution

by:
blue-genie earned 2000 total points
ID: 22983649
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
 

Author Comment

by:lexshine
ID: 22991952
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
 
LVL 39

Expert Comment

by:blue-genie
ID: 22992322
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
 

Author Closing Comment

by:lexshine
ID: 31514271
thanks!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I know the transition can be hard. We got used to the ease of use ActionScript 2 had, but honestly, it became problematic later on, especially if designers were involved in the project and found it easy to add code as they saw fit. So, this artic…
While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question