Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash





See Related Forum Messages: Follow the Links Below to View Complete Thread

Loading Data From Text File To Multidimensional Array
New to Actionscript here so please bear with me, I'm trying to learn. I'm developing a simple application which loads specific information based on user input. The code below works fine and does exactly what I want, however, I want to be able to load the raceInfo multidimensional array information from an external text file. I've read alot about doing this but have not been successful and am somewhat frustrated. Can someone help me and teach me how to get that information from a text file? Thanks in advance!

//Multidimensional Array
raceInfo=[["1","Bob Smith","Fast","Slow as Lightening"],["2","John Doe","Speedy Car","Running Fast"]];

var testText1 = testText1_txt.text;
var testText2 = testText2_txt.text;
//trace(testText1);
//trace(testText2);

loadBtn.onRelease = function () {

for(i=0;i<raceInfo.length;i++) {
if(testText1 == raceInfo[i][0]) {
_root.createEmptyMovieClip("container1",1);
container1.loadMovie("/scoutpics/" + testText1 + ".jpg");
container1._x = 150;
container1._y = 150;
scoutName1_txt.text = raceInfo[i][1];
carNumber1_txt.text = raceInfo[i][0];
carName1_txt.text = raceInfo[i][2];
slogan1_txt.text = raceInfo[i][3];
}
}

for(i=0;i<raceInfo.length;i++) {
if(testText2 == raceInfo[i][0]) {
_root.createEmptyMovieClip("container2",2);
container2.loadMovie("/scoutpics/" + testText2 + ".jpg");
container2._x = 650;
container2._y = 150;
scoutName2_txt.text = raceInfo[i][1];
carNumber2_txt.text = raceInfo[i][0];
carName2_txt.text = raceInfo[i][2];
slogan2_txt.text = raceInfo[i][3];
}
}

resetBtn.onRelease = function () {
testText1_txt.text = "";
testText2_txt.text = "";
container1._visible = false;
container2._visible = false;
scoutName1_txt.text = "";
scoutName2_txt.text = "";
carNumber1_txt.text = "";
carNumber2_txt.text = "";
carName1_txt.text = "";
carName2_txt.text = "";
slogan1_txt.text = "";
slogan2_txt.text = "";
}
}

Import .txt File As A Array (multidimensional)
Ok- this is a program for self use, so i can just have the outside .txt file in the same folder as the .fla (i know this.)

So- how to format the .txt file so that when i do this:


Code:
loadVarsText = new LoadVars();
loadVarsText.load("Rapsodygap.txt");
loadVarsText.onLoad = function(success) {
if (success) {
trace(this.gap);
}
}
firstdata = this.gap[0,1]
I want rapsodygap.txt to look and do something like this:

Code:
&variablename= [[1.307,1],[1.407,2],[1.503,3]]
Practical aspect- i'm getting the program to import this text file, and i'm gonna do some calculations with the arrays (first number is a time (in ms) 2nd number is how many beats this is away from the last one.)

its a bpm caculator, but VERY EXACT, for when checking the waveform of audio.

I could do it with calculator, but the point is that i'm about to attempt a 17 minute song, and so i need a program to do the calculations. I HAVE IT ALL CODED NOW ALL I NEED IS TO IMPORT MY ARRAYS!!!! *sighs*

Create A Multidimensional Array From Txt File
that's the text within the txt file.. i generated a while ago.. and the page where i got the tutorial from is no longer avaiable

"noSplits=4&p=problema1!raspuns1!raspuns2!raspuns3 !raspuns4!raspuns5~problema2!raspuns1!raspuns2!ras puns3!raspuns4!raspuns5~problema3!raspuns1!raspuns 2!raspuns3!raspuns4!raspuns5~problema4!raspuns1!ra spuns2!raspuns3!raspuns4!raspuns5"

i remember that it used the split() function for a number of noSplits(eg: 4).. i need a multidimensional array like this:

a[1][0]=problema1
a[1][1]=raspuns1
a[1][2]=raspuns2
a[1][3]=raspuns3
a[1][4]=raspuns4
a[1][5]=raspuns5
a[2][0]=problema2
.....................
a[4][5]=raspuns5

if someone could help me i would greatly apreciate it.. the txt file doesn't need to have the same sintax as the one i wrote.. i want to create an array with 100*6 components.. and read all the values from the txt file.. thank you very much again

Create A Multidimensional Array From Txt File
that's the text within the txt file.. i generated a while ago.. and the page where i got the tutorial from is no longer avaiable

"noSplits=4&p=problema1!raspuns1!raspuns2!raspuns3 !raspuns4!raspuns5~problema2!raspuns1!raspuns2!ras puns3!raspuns4!raspuns5~problema3!raspuns1!raspuns 2!raspuns3!raspuns4!raspuns5~problema4!raspuns1!ra spuns2!raspuns3!raspuns4!raspuns5"

i remember that it used the split() function for a number of noSplits(eg: 4).. i need a multidimensional array like this:

a[1][0]=problema1
a[1][1]=raspuns1
a[1][2]=raspuns2
a[1][3]=raspuns3
a[1][4]=raspuns4
a[1][5]=raspuns5
a[2][0]=problema2
.....................
a[4][5]=raspuns5

if someone could help me i would greatly apreciate it.. the txt file doesn't need to have the same sintax as the one i wrote.. i want to create an array with 100*6 components.. and read all the values from the txt file.. thank you very much again

Comparing Between An Array And A Multidimensional Array
Hi all, this is my first post.
I have only been working with flash for a couple of years, but I know my way around it pretty well. I usually can find answers to any problems I have through searching, but I seem to be stuck on this one....

I am trying to compare an element in an array to an element in an multidimensional array. Here is my code

var songArray:Array = new Array([["q"],["l8"],["l6"]],[["r"]],[["q"],["s5"]]);
var lineArray:Array = new Array("l8","s8","l9","s9");

var tempLine = lineArray[0];
var tempNote = songArray[0][1];

trace(tempLine) // l8
trace(tempNote) // l8

if(tempLine == tempNote) {
trace("True");
} else {
trace("False");
} // False

Why is this?
I appriciate anyones input

Thanks
builder

Flat Array Vs Multidimensional Array
For a game I'm making I've tried to stick with using flat arrays as much as possible because I read somewhere that its faster than using multidimensional arrays. I just need to know if anyone knows or can point me to any place which discusses the speed difference (if there is any).

Using multidimensional arrays would make my coding much easier but if its slower than flat arrays I'm willing to persevere for the better execution time.

Any thoughts?

Multidimensional Array
I am creating a tile-based game, and need large 2D arrays to map out the territory. As it is a large area, and I want to be able to add large objects, I thought that a map function would be good:

map=new Array();
//
Movieclip.createMap= function(beginCol,beginRow,endCol,endRow) {
for(var i=beginCol;i<endCol;i+=1)
for (var j=beginRow;j<endRow;j+=1) {
_root.map[i][j]=1;
}
}
//
Using this I should be able to map out any rectangular area.

The problem is that the map array is only 1 dimension, it doesnt accept the [i][j] parameters. And as it will be a 50*50 tile game, i dont want to declare

map[1]=new Array();
map[2]=new Array(); etc etc

Any ideas on how to declare an empty multidimensional array?

Multidimensional Array
hi I am trying to figure out multidimensional arrays...

I need an array to hold an answer + divider + score...
This is my code....
The dividers are there so I can use them to split the string in authorware
[code]

question = new Array(answer,divider,score);
question[1] = ["apples", " | ", 1];
question[2] = ["bananas", " | ", 1];
trace(question);
outputscore = question.join(" || ");
trace(outputscore);


Is this right?
Also how can I access the answer value of say question [1] ?

can I use question[1].answer = "peaches" ?

any help greatly appreciated!

XML->Multidimensional Array
Hello,

I am trying to put an XML file into a three dimensional array.I have searched this forum for help, but ít didn't help me. Can anyone tell me what's wrong with this function?

xmlRails.onLoad = function(succes){
var i,j,k;
var rails = new Array();

xmlRails = xmlRails.firstChild;

for(i=0;i<xmlRails.firstChild.childNodes.length;i+ +)
{
xmlRails[i] = new Array();
for(j=0;j<xmlrails.firstChild.childNodes[i].childNodes.length;j++)
{
xmlRails[i][j] = new Array();
for(k=0;k<xmlRails.firstChild.childNodes[i].childNodes
[j].childNodes.length;k++)
{
trace(xmlRails.firstChild.childNodes[i].childNodes
[j].childNodes[k]);
rails[i][j][k]=xmlRails.firstChild.childNodes[i].childNodes
[j].childNodes[k];
trace(rails[i][j][k]);
}
}
}
}
I can look into the XML file, but the trace on the array turns up 'undefined'.
Help? PLease? Any help? I'm desperate!

Multidimensional Array
Hi,

I'm strugling for hours now on a multidimensional array.
I load an XML-file and put the data in three array's.
The arPicture array should be multidimensional. In the XML-format i've got
<part>
<text>Blablabla</text>
<hulp>some text</hulp>
<pictures><picture>blabla.gif</picture><picture>blablabla.gif</picture></pictures>
</part>

As you can see there can be more than one pictures in a <part>-tag.
In the code below I've tried to loop trough all the XML-nodes. When a <pictures>-node is found, it loops a second to find all the pictures.
So the result should be:
arPicture[0][0] = blabla.gif
arPicture[0][1] = blablabla.gif

That works fine, until there's a new loop through the first level (<part>-node)
for some reason any value in the arPicture[0][x] is lost, and returns "undefined". The arPicture[1][x] is ok then.

I can't figure why?

Can anyone help? (quite urgent...)
Thanks in advance...
.NET Freak


Code:
var arText = new Array();
var arHelp = new Array();
var arPicture = new Array();
var xmlParser:XML = new XML();

xmlParser.ignoreWhite = true;
xmlParser.load("xml/isvBrugge.xml");
xmlParser.onLoad = function(success:Boolean) {
if (success) {
Title.text = xmlParser.firstChild.firstChild.firstChild.firstChild.nodeValue;
if (xmlParser.firstChild.firstChild.hasChildNodes()) {
i = 0;
x = 0;
for (var aPart = xmlParser.firstChild.firstChild.firstChild; aPart != null; aPart=aPart.nextSibling) {
if (aPart.hasChildNodes()) {
for (var aNode = aPart.firstChild; aNode != null; aNode=aNode.nextSibling) {
if (aNode.nodeName == "Text") {
arText[i] = aNode.firstChild.nodeValue;
}
if (aNode.nodeName == "Hulp") {
arHelp[i] = aNode.firstChild.nodeValue;
}
if (aNode.nodeName == "Pictures") {
x = 0;
for (var aPic = aNode.firstChild; aPic != null; aPic=aPic.nextSibling) {
arPicture[i] = new Array();
arPicture[i][x] = aPic.firstChild.nodeValue;
x++;
}
trace(arPicture);
}
}
i++;
}
x++;
}
}
_root.DelayController.play();
} else {
Title.text = "Loading XML-file";
}
};

Multidimensional Array
This is something not getting right

ar=new Array();
ar[8,0]=1;
ar[5,3]=8;
for(i=0;i<9;i++){
trace(ar[i,0]+" "+ar[i,1]+" "+ar[i,2]+" "+ar[i,3])
}

is delivering the results

1 undefined undefined 8
1 undefined undefined 8
1 undefined undefined 8
1 undefined undefined 8
1 undefined undefined 8
1 undefined undefined 8
1 undefined undefined 8
1 undefined undefined 8
1 undefined undefined 8

But i think it should go like

undefined undefined undefined undefined
undefined undefined undefined undefined
undefined undefined undefined undefined
undefined undefined undefined 8
undefined undefined undefined undefined
undefined undefined undefined undefined
undefined undefined undefined undefined
undefined undefined undefined undefined
1 undefined undefined undefined





Plz help. I think i doesn't know flash.

Multidimensional Array?
basically I have an array of numerical values that change depending on which button is pressed, and they need to be displayed as text but sorted numerically... I thought a multidimensional array would work, but I cant get it to sort right. Is this possible to do, or is there another way to accomplish this thats relatively easy?

The idea is for totals_array to calculate the total value and sort it numerically then name_array replaces that value with the appropriate title and is traced.

button code:


Quote:




on(press) {

// arrays are all created at frame 1 then used on button presses
totals_array[0] = fcsg_array[0] + nutrition_array[0];
totals_array[1] = fcsg_array[1] + nutrition_array[1];

name_array[0] = "Colorado Springs";
name_array[1] = "Minneapolis";

totals_array.sort(Array.NUMERIC);
trace(totals_array);




I am using FL8 also

Any help is appreciated!

Thanks

Multidimensional Array Help
Hi
I have an array with 12 elements
mates =["6", "bob", "4", "10", "fred", "1", "7", "joe", "3", "14", "mark", "7"];

I am trying to convert this into a mutidimensional array
so the new array would look like

newArray=[6,bob,4],[10,fred,1],[7,joe,3],[14,mark,7]

I need to be able to spilt the original array into 4 parts of 3 and then sort the array into order based on the first element.

the final structure in order would look like
[6,bob,4], [7,joe,3],[10,fred,1],[14,mark,7]

I am not sure how to do this can anyone please help?

Help With Multidimensional Array
I am having a problem with creating and loading data into a multidimensional array. I want to create an array to hold data from blog entries in a database. Each array in the larger array will hold the data for each column in the database.

I have tested and the data is coming into Flash fine and is in the LoadVars variable. However the final trace statement in the loop that is loading the data in the array shows "undefined" for the array element.

What am I missing? (code is below)


var blogItems:Array = new Array("artID","artTitle","artDate","artLoc","artCa t","art");

// get blog list data into an array we can use elsewhere
var records:Number = this["records"];
var i:Number;

blogItems["artID"] = new Array();
blogItems["artTitle"]= new Array();
blogItems["artDate"]= new Array();
blogItems["artLoc"]= new Array();
blogItems["artCat"]= new Array();
blogItems["art"]= new Array();

for (i=0; i < records; i++) {
blogItems["artID"][i] = this["artID"+i];
blogItems["artTitle"][i] = this["artTitle"+i];
blogItems["artDate"][i] = this["artDate"+i];
blogItems["artLoc"][i] = this["artLoc"+i];
blogItems["artCat"][i] = this["artCat"+i];
blogItems["art"][i] = this["art"+i];
trace (blogItems["artID"][i]);
}

Multidimensional Array
Hi!
My first post here

i have a problem. I need to pharse xml data and put it in an multidimensional array like this:
slides->slide[0]->subSlides[0]->slideHeader, slideText
slides->slide[0]->subSlides[1]->slideHeader, slideText
slides->slide[0]->subSlides[2]->slideHeader, slideText
slides->slide[1]->subSlides[0]->slideHeader, slideText
slides->slide[1]->subSlides[1]->slideHeader, slideText
slides->slide[1]->subSlides[2]->slideHeader, slideText
And so forth...

and the xml looks like this:
<channel>
<slides>
<slide>
<subSlides>
<slideHeader>Header</slideHeader>
<slideText>Text</slideText>
</subslides>
<subSlides>
<slideHeader>Header</slideHeader>
<slideText>Text</slideText>
</subslides>
<subSlides>
<slideHeader>Header</slideHeader>
<slideText>Text</slideText>
</subslides>
</slide>

<slide>
<subSlides>
<slideHeader>Header</slideHeader>
<slideText>Text</slideText>
</subslides>
<subSlides>
<slideHeader>Header</slideHeader>
<slideText>Text</slideText>
</subslides>
<subSlides>
<slideHeader>Header</slideHeader>
<slideText>Text</slideText>
</subslides>
</slide>
</slides>

Anyone that knows a solution?
I've made a whole bunch of tries but always end up with a error (#1010 or something like that).

Thanx!
//Martin

Multidimensional(3d) Array
ok, trying to make a multidimensional array that holds: questions, answers, and which answer is correct. all this info is stored in an external XML file that contains other text as well.

right now i have this:
var allReview:XMLList = theCaption.review.question.text();
var allAnswers:XMLList = theCaption.review.question.answer.text();
var allCorrectAnswers:XMLList = theCaption.review.question.answer.attributes();
trace("review questions: " + allReview);//traces out all the questions
trace("review questions: " + allReview[0]);//traces 1st question

now i believe i will make the correct answer a boolean value in a attribute in the XML file.

keep in mind some questions will have 2 answers and some will have 4.

one column for questions, one for answers, and one for boolean values.

how do i go about storing all this info in a multidimensional array???? if there's 4 answers to on question- there's no point in storing the question 4 times.

Please some type of direction on this issue would be great!!!

Multidimensional Array Help
hey people,
i am trying to create a dynamic menu with a submenu. i simply setted up a xml file which is looking like that:


ActionScript Code:
<menu>
        <item pos = "main" type = "movie" cat = "none" sub = "no">
            <title>news</title>
            <content>news.swf</content>
        </item>
        <item pos = "main" type = "movie" cat = "none" sub = "no">
            <title>projects</title>
            <content>pr.swf</content>
        </item>
        <item pos = "main" type = "button" cat="none" sub = "yes">
            <title>office</title>
            <content></content>
        </item>
        <item pos = "sub" type = "text" cat="büro" sub = "no">
            <title>bio</title>
            <content><![CDATA[Here some text for content]]></content>
        </item>
        <item pos = "sub" type = "text" cat="büro" sub = "no">
            <title>qualification</title>
            <content><![CDATA[Here some more text]]></content>
        </item>
        <item pos = "sub" type = "text" cat="büro" sub = "no">
            <title>internships</title>
            <content><![CDATA[Bla bla]]></content>
        </item>
        <item pos = "main" type = "button" cat="none" sub = "yes">
            <title>press</title>
            <content></content>
        </item>
        <item pos = "sub" type = "text" cat="presse" sub = "no">
            <title>won prizes</title>
            <content><![CDATA[...]]></content>
        </item>
        <item pos = "sub" type = "movie" cat="presse" sub = "no">
            <title>publication</title>
            <content>p.swf</content>
        </item>
        <item pos = "sub" type = "text" cat="presse" sub = "no">
            <title>exhibitions</title>
            <content><![CDATA[More text]]></content>
        </item>
        <item pos = "sub" type = "movie" cat="presse" sub = "no">
            <title>interviews</title>
            <content>int.swf</content>
        </item>
        <item pos = "main" type = "movie" cat="none" sub = "no">
            <title>contact</title>
            <content>contact</content>
        </item>
        <item pos = "main" type = "text" cat="none" sub = "no"> 
            <title>copyrights</title>
            <content><![CDATA[sdf]]></content>
        </item>
    </menu>

now i had following idea:
i wanted to sort the nodes by asking for the position in the menu and if they have a sub menu (attributes pos & sub).
so i wrote a function which is looking like that:


ActionScript Code:
function sortButtons(bLabel:String, bType:String, bPos:String, bCat:String, bID:Number, bSub:String):Array {
    var menu:Array = new Array(new Array(), new Array());
    var bString = bLabel+"|"+bType+"|"+bPos+"|"+bCat+"|"+bID;
   
    if(bSub == "no" && bPos == "main"){
        counterSub = 0;
        trace("menu["+counter+"]["+counterSub+"] pushed "+bString+" ("+bSub+", "+bPos+")");
        menu[counter] = bString;
        counter++;
    }
    else if(bSub == "no" && bPos == "sub"){
        counterSub++;
        trace("menu["+(counter-1)+"]["+counterSub+"] pushed "+bString+" ("+bSub+", "+bPos+")");
        menu[(counter-1)][counterSub] = bString;
    }
    else if(bSub == "yes" && bPos == "main"){
        counterSub = 0;
        trace("menu["+counter+"]["+counterSub+"] pushed "+bString+" ("+bSub+", "+bPos+")");
        menu[counter] = bString;
        counter++;
    }
    else {
        counterSub = 0;
        trace("menu["+counter+"]["+counterSub+"] pushed "+bString+" ("+bSub+", "+bPos+")");
        menu[(counter-1)][counterSub] = bString;
        counterSub++;
    }
    trace(menu);
    return menu;
}

the trace("menu["+counter+"]["+counterSub+"] pushed "+bString+" ("+bSub+", "+bPos+")"); is outputting the menu array totally right. but when i'm tracing menu at the end of the function it is stuck at the second button. do you have an idea, how this could be realized?

oh and by the way: the function is called in the onLoad function in a simple for-loop:


ActionScript Code:
for(i = 0; i < nodesNumber; i++){
            var labels:String = String(nodes[i].childNodes[0].firstChild.nodeValue);
            var type:String = String(nodes[i].attributes.type);
            var pos:String = String(nodes[i].attributes.pos);
            var cat:String = String(nodes[i].attributes.cat);
            var subMenu:String = String(nodes[i].attributes.sub);
           
            buttons = sortButtons(labels, type, pos, cat, i, subMenu)
        }

i really appreciate your help!
thanks a lot!

How To Use Multidimensional Array
Hi,

I need to store my values in to Multidimensional Array is there any special syntax or we can use the same as AS2

Thanks,

Multidimensional Array
How to declare and define a multidimensional array in action script?

Multidimensional Array
How to call a function from a movie which is defined in another movie?

MultiDimensional Array
I am trying to create an array that holds some info for each item in the array how would I do that?
I want to add a two variables to an array that are essentialy one item in the array. Also how would I acess them later?
a= 1;
b = 2;
myArray = [];
myArray.push [??? this is were I confused with the syntax.
I would really appreciate the help.
Thanks

Multidimensional Array
Hi, i have some problem witha multidimensional array.
Now explain:

I've create a structure like a Table, the data are take from a bidimensional array. I want include some button to order by a column for example order by code, name etc.

For ordering array i use sortOn() command but the result is anomalous, some time there is a change between 2 column and other time the array is the same in the same order.

Someone can help me please.

P.S. Sorry for my english, i hope to be right.

Nice

Multidimensional Array
how do i create an array of 30x30 elements? i have tried


Code:
p = [[0],[0]];
but it doesn't seem to work.. please help me ASAP

Multidimensional Array
I have an array/Object:

Code:
[0] = mm_name=image1.jpg,mm_path=img/req1,mm_keywords=keyword1
[1] = mm_name=image2.jpg,mm_path=img/req9,mm_keywords=my black cat
[2] = mm_name=image3.jpg,mm_path=img/req7/new,mm_keywords=a brown dog
I want to convert it to a multidimensional array (i think?) so I can reference, like so:

Code:
trace(myArray[1]["mm_name"]); // image2.jpg
trace(myArray[2]["mm_keywords"]); //a brown dog
Any suggestions are greatly appreciated!

XML To Multidimensional Array
Hi There,

First of all thanks for reading this.

I'm trying to build a trivia slideshow similar to what you would see at the movie theater. I can populate two arrays, one for questions and one for answers. But in order to randomize the output of the question/answers (making sure that the right answers stay with the right questions) I am trying to put them into a multidimensional array. Then later I'll pull a random from that to get my output for my sprite.

So my xml looks like this:

Code:
<trivia>
<entry question="How do you feel?" answer="I feel Fine"/>
<entry question="Are you tall?" answer="I am tall"/>
<entry question="Are you sleeping?" answer="I am asleep"/>
</trivia>
and my actionscript looks like this:


Code:
var xml:XML = new XML(); //setup initial vars to retreive xml data
var loader:URLLoader = new URLLoader();

loader.load(new URLRequest("trivia.xml")); //xml file is local to swf
loader.addEventListener
(Event.COMPLETE,function(evt:Event):void //wait for xml to load
{ xml = XML(evt.target.data);
var num:Number = xml.entry.length();
trace(num);
trace(xml);
var trivquest:Array = new Array();
var trivanswer:Array = new Array();

for (var i:Number = 0; i < num; i++)
{
trivquest[i] = xml.entry.@question[i].toXMLString();
trivanswer[i] = xml.entry.@answer[i].toXMLString();
}

var trivlist:Array = new Array((trivquest[i]),(trivanswer[i]));
trace(trivlist);
}
);

So my multiDarray is trivlist, but it's not getting populated properly.

Any advice/help is greatly appreciated!

Tony

Multidimensional Array
Hi, i have some problem witha multidimensional array.
Now explain:

I've create a structure like a Table, the data are take from a bidimensional array. I want include some button to order by a column for example order by code, name etc.

For ordering array i use sortOn() command but the result is anomalous, some time there is a change between 2 column and other time the array is the same in the same order.

Someone can help me please.

P.S. Sorry for my english, i hope to be right.

Nice

Multidimensional Array
how do i create an array of 30x30 elements? i have tried


Code:
p = [[0],[0]];
but it doesn't seem to work.. please help me ASAP

Multidimensional Array On The Fly
I'm going a bit...crazy...with this problem.

I need to create a multi-dim array that keeps track of movieclip references and under each movieclip references, more references to other clips.

So lets start with the first level movieclips:

mArray = [mc1, mc2, mc2, mc4, mc5];

and lets add a couple other references under it:

mArray[mc1] = [mc6, mc7];
mArray[mc2] = [mc8, mc9];
mArray[mc3] = [mc10, mc11];

I'll never be assigning these on first instance, I need to be able to push new references into the arrays as I go.

After this I'll need to be determine the clips related to each movieclip. So if I want to determine clips under mc2 I want to do:

mArray[mc2].length and recursively scan through it's children and command them as I would like.

I'm not sure if this is possible but it would make my life a "heck" of a lot easier. so my question is how do I add children to each array reference as I go?

thanks in advance.

Multidimensional Array
Hello!
I't trying to create a multidimensional array of the following kind:

let's say we have a list of cities:
Rome, Paris, London
and a list of neighborhoods for each(i.e: rn1,rn2,...for Rome)
How can I create one array that holds all that information like:

var travel = new Array()
//and the travel array hold information like:
Rome(rn1,rn2,rn3),Paris(pn1,pn2),London(ln1,ln2,ln3,ln4)

so later I could access travel[0] = Rome, travel[1] = Paris
and...
travel[0][0] = rn1
travel[1][1] = pn2

or something like it...
thanks!

Multidimensional Array Problem
Hi there,

I am putting together a very large ROI calcualtor for a client. It has an input screen, an output screen and a whole spreadsheet full of variables to calculate everything up with.

Since there is such a huge amount of 'assumtion' variables to work with I've decided to putthem all into a mutidimesional array and call them up that way (ie: Assumptions[2][1]). My problem comes in when i build my second mutidimensional array using a combination of input values and values from the first array.

I found out that i can't call an array item when i'm trying to build an array because of the brackets "[" i think.

Here's what it looks like:
array2 = [ [((e14 + ((array[0][0])*e14))* 40 * 52),((e14+(array1[0][1]*e14))*40*52),((e14+(array1[0][2]*e14))*40*52)],
[moredata,moredata,moredata] ];

Does anyone know a workaround for this?

I tried the old JavaScript infront of the [ and ] to show that i'm not trying to start or end an array but that doesn't work in Actionscript.

Does this make any sense?
Thanks for any help you can give me.

[MX] Populating A Multidimensional Array
I am relatively new to Flash MX. While I've done a pretty good job
in the last two days manipulating XML files and arrays, the following
challenge finally has my head spinning. Could anyone help me out? I've managed to work the XML file okay, but going nuts with the array itself.

I have the following XML file structure to work with, and need to
bring it into a multidimensional array so that I can read it often
to populate UI components dynamically.

XML File "productlist.xml" has the following structure.
(use of square brackets instead of angle brackets to allow display in this forum only)...
----------------------------------------------------------------
[?xml version="1.0"?]
[products]
[item]
[name]Product Name[/name]
[desc]Product Description Here[/desc]
[image]image.jpg[/image]
[price]xxx.xx[/price]
[option]
[optname]Option Name[/optname]
[optdesc]Option Description here[/optdesc]
[optimage]optimage.jpg[/optimage]
[optprice]zzz.zz[/optprice]
[/option]
[/item]
[/products]
---------------------------------------------------------------
Of course the structure will include many items. Some items
will have NO options, while others may have ten options.
All other elements are fixed.

I believe a four-dimensional array is needed. Might be wrong.
A diagram of how I am intending to access the array appears below:
//-------------- MY IMAGINED ARRAY STRUCTURE -----------------------//
// products[x] -- (a specific product)
// products[x][0] -- (product x name)
// products[x][1] -- (product x desc)
// products[x][2] -- (product x image)
// products[x][3] -- (product x price)
// products[x][4] -- (product options array)
// products[x][4][y] -- (product x option y)
// products[x][4][y][0] -- (product x option y name)
// products[x][4][y][1] -- (product x option y desc)
// products[x][4][y][2] -- (product x option y image)
// products[x][4][y][3] -- (product x option y price)
//-----------------------------------------------------------------//

I have a good chunk of code working already, but I seem to be
having trouble over-writing sections of the array while reading
through the XML file.

I think I remember seeing someone else with a similar problem. When I trace in the middle of iterating through the file, the array seems to be populating correctly. But when I trace again after the looping is complete, the entire array is filled with the elements from the last major node of the XML file.

Could someone help me out with code for this? I've been researching and fiddling all day to no end.

Visious Multidimensional Array...
Hi
I never use multi dimensional arrays before, but for a project Im doing I would like to combine a bunch of arrays into one ...

First I load some strings from txt for testing purpose..
the txt.:


Code:
&dato=01-01-2005,10-01-2005
&juliansk=1,10
&navn=fest1,fest2
&antal=10,23


Ok.. now I load, split and TRY.. to combine these.. but the trace at the bottom is empty or undefined..


Code:
my_date = new Date();
year = my_date.getFullYear();
all_years = new LoadVars();
all_years.load("data.txt");
all_years.onLoad = function(success) {
if (success) {
dato = this.dato.split(",");
jul = this.juliansk.split(",");
navn = this.navn.split(",");
antal = this.antal.split(",");
size = antal.length;
opdelArray(dato, jul, navn, antal, size);
} else {
trace("Det bare noget lort!");
}
};
stop();
function opdelArray(dato, juliansk, navn, antal, size) {
my_date = new Date();
year = my_date.getFullYear();
var j = 0;
var k = 0;
fest_data = new Array(size);
fest_data[0] = year;
for (var i = 0; i<size; i++) {
temp = dato[i].split("-");
trace(temp[2]);
if (fest_data[j] == temp[2]) {
fest_data[j][k] = ""+dato[i];
fest_data[j][k].push(new Array(1));
fest_data[j][k][0] = ""+juliansk[i];
fest_data[j][k][0].push(new Array(1));
fest_data[j][k][0][0] = ""+navn[i];
fest_data[j][k][0][0].push(new Array(1));
fest_data[j][k][0][0][0] = ""+antal[i];
k++;
} else {
j++;
k = 0;
fest_data[j] = ""+temp[2];
fest_data[j].push(new Array(size));
fest_data[j][k] = ""+dato[i];
fest_data[j][k].push(new Array(1));
fest_data[j][k][0] = ""+juliansk[i];
fest_data[j][k][0].push(new Array(1));
fest_data[j][k][0][0] = ""+navn[i];
fest_data[j][k][0][0].push(new Array(1));
fest_data[j][k][0][0][0] = ""+antal[i];
k++;
}
}
trace(fest_data)
}


If someone could guide me a bit.. I made this from and example and don't really know where to begin searching for errors..

thanks...

[F8] Adding A Multidimensional Array Together?
I've got a m.d array which I am filling with values. Is there a quick way to add up every item? Maybe a function built in?

[F8] XML Data Into A Multidimensional Array
This multidimenisonal array is going to contain a site's navigation.

The XML loads, then calls the "linkAdder" function to parse the XML node values. It checks to see if there are child nodes of the XML data it's reading, and if so, creates another array within the value it's populating and calls itself. What I'm going for is a structure like this:


PHP Code:




var mainNav:Array = Array('A', 'B', 'C', 'D', 'E', 'F', 'G');
mainNav[4] = Array('D', 'D-A', 'D-B', 'D-C', 'D-D', 'D-E');
mainNav[4][1] = Array('D-A', 'D-A-A', 'D-A-B', 'D-A-C');
trace(mainNav);





I'm running into problems though. Instead of mainNav[4] being 'D', it's always replaced with 'D-A'. In other words, the value from xml_data.childNodes[4].childNodes[0] is replacing the value in xml_data.childNodes[4].

I've been looking at this too long, and my brain's turning to mush. I know my XML is formated properly. Can anyone help in any way?


PHP Code:




function loadLinkXML() {
    var link_xml:XML = new XML();
    link_xml.ignoreWhite = true;
    link_xml.onLoad = function(success) {
        if (success) {
            _global.mainLinks = Array();
            linkAdder(link_xml.firstChild, _global.mainLinks);
            trace(_global.mainLinks);
        }
    };
    link_xml.load("nav.xml");
}
function linkAdder(xml_data:XMLNode, container:Array) {
    for (var i:Number = 0; i < xml_data.childNodes.length; i++) {
        if (xml_data.childNodes[i].firstChild != undefined) {
            container[i] = Array();
            container[i].push(xml_data.childNodes[i].attributes.display_name);
            linkAdder(xml_data.childNodes[i], container[i]);
        } else {
            container.push(xml_data.childNodes[i].attributes.display_name);
        }
    }
}
loadLinkXML();

[F8] Sorting A Multidimensional Array
I have an array thats stores an object;

chatters_arr = new array()
chatter = function(name, age, gender){
this.name = name
this.age = age
this.gender = gender
}

for(i=0;i<chatters.length;i++){
chatters_arr[i] = new chatter(
chatters.attribute.name,
chatters.attribute.age,
chatters.attribute.gender,
)
}

Now each time a chatter enters / leaves the room I will push a new object into the array or remove. Afterwards I want to sort the chatters alphabetically. How do I do this?

I know how to use the array sort, but how do I use it to sort the entire array based on the property of an ojbect stored inside?

Thanks.

[F8] Multidimensional Array For Nav Menu?
Ok, I have a feeling that I'm going about this all wrong, but anywho:

I have a site with a three level nav bar. I've created movie clips for the menu elements (easier for positioning) with mc_level1, mc_sub1, mc_sub2, mc_tert1_2, mc_tert2_1, etc.

In my actionscript, where I'm defining menu behavior/tweens, I want to have a multidimensional array to keep the elements of the menu, so that:

menu = new Array(4)
menu[0] = new Array(2)
menu[0][1] = new Array(mc_tert_0_0, mc_tert_0_1, mc_tert_0_2)

but I'd also like to be able to reference level 1 and level 2 menu items by the array like:

menu[0] = mc_Support
menu[0][1] = mc_Volunteer
menu[0][1][2] = mc_tert_0_2


Does this make sense? Are you allowed to have aliases for array levels, or should I just create three arrays?

[F8] Send Multidimensional Array To PHP
Hi Everyone,

Here's my situation, I'd like to send the data in a multidimensional array to php so it can commit the data to a mysql database. The array associates product numbers to matching images (sometimes more than one image, in which case there will also be an identifier for each image). For example:

product_array[12345][0] = new Array(image1, desc1);
product_array[12345][1] = new Array(image2, desc2);
product_array[12346][0] = new Array(image3);

My problem is getting this out to php while maintaining the structure. When I just send the array, it gets flattened into one long string that's completely useless.

I wonder if there is a way to send the whole array as an object or something to php, since I know arrays can be sent via post (i.e. an html form array), by maybe changing the loadVars.contentType property or messing with the LoadVars.AddRequestHeader method.

If not, can someone recommend a way of creating variables on the loadVars object whose name references the product number and whose value contains the nested array (if this gets flattened, i think i can figure how to parse it).

Thanks for any suggestions.

_b

[F8] Multidimensional Array Of Different Lengths (and A Bit Of XML Too)
Hi there,

I'm getting to grips with multidimensional arrays so i can store projects and images from each project loaded from an xml file for a photography website. i won't know the total number of projects as they will be added to so i need to dynamically create arrays to store new projects. are multidimensional arrays the way to do this?

if so, i was wondering if arrays within the main arrays could be of different lengths? this is because there is no set limit on the number of photos in a project.

so instead of:
bigA[0] = 0,1,2,3
bigA[1] = 0,1,2,3
bigA[2] = 0,1,2,3

it would be:
bigA[0] = 0,1,2
bigA[1] = 0,1,2,3,4,5
bigA[2] = 0,1,2,3

at the moment i'm creating the arrays using for...loops and will be using for...loops to cycle through and store the xml data.

any help regarding multidimensional arrays much appreciated and any tips on dynamically using xml data greatfully received.

cheers,

David

Multidimensional Array Problems
I'm not sure what I'm doing wrong, but I have an array that looks like this:
PHP Code:



function oFish(oCreature, oPopName, oDesc, oHabitat, oFood, oPredators):void{
    this.creature = oCreature;
    this.popName = oPopName;
    this.desc = oDesc;
    this.habitat = oHabitat;
    this.food = oFood;
    this.predators = oPredators;
}
    //
var fishArray:Array = new Array();
fishArray[0] = new oFish("Black_Rockfish_mc", "Black Rockfish", "", "", "", "");
fishArray[1] = new oFish("Blue_Rockfish_mc", "Blue Rockfish", "", "", "", "");
fishArray[2] = new oFish("Bluestripe_Perch_mc", "Bluestripe Perch", "", "", "", "");
fishArray[3] = new oFish("Buffalo_Sculpin_mc", "Buffalo Sculpin", "", "", "", "");
fishArray[4] = new oFish("Cabezon_mc", "Cabezon", "", "", "", "");




and I keep getting this error on each array line:
Code:
1048: Method cannot be used as a constructor.

[AS3] Amfphp Multidimensional Array
Hello, I have a section of a php script that sends my as3 flash file a multi dimensional array via AMFPHP.

PHP Code:




$data = array();
            while ($mail_row = mysql_fetch_assoc($results_mail))
            {
                array_push($data, $tempdata = array($mail_row['from_player_id'], $mail_row['_sent'], $mail_row['subject'], $mail_row['message']));
            }
            if ( mysql_num_rows( $results_mail ) == 0 )
            {
                return "0,No Mail";
            }
            return "0,".$data;







That will take specific data from every row of results and push it into an array. For each row found, it creates a new row of an array.

So im sure I need to do something alone the lines of looping through _data[1] for in, but can't get a working result. It either traces 'Array', or nothing at all.

Thanks!

Multidimensional Array Assignment
Hiya Guys,

I have done a search on the forum but coiuldn't see the same problem and I'm probably just having a brain fart anyway but...

this piece of code works...


Code:
Var GridArr=new Array()
for (var i=0;i<10;i++){
GirdArr[i]=123
}
trace(GridArr)
but this doesn't...

Code:
var GridArr= new Array()
for (var i=0;i<10;i++){
for(var j=0;j<10;j++){
GridArr[i][j]=123
}
}
trace(GridArr)
Anybody know why?

I'm sure I must have done this a million times before and it has worked but i cannot get it to work for the last 24 hrs!!

cheers for any help

Z

Multidimensional Array > TreeMenu
hi,

im trying to build a tree menu from a multidimensional array with lack of luck.
The array get its elements form a mysql db and has a parent - child relationship. what makes it look something like this;


Code:
var arr:Array = new Array
(
[0, 'root', 0],
[21, 'norwegian', 0],
[22, 'english', 0],
[23, 'Om mitt firma', 21],
[24, 'About My Company', 22],
[25, 'Kontakt', 21],
[26, 'Contact', 22],
[27, 'Tjenester', 21],
[28, 'Service', 22],
[29, 'tjeneste1', 27],
[210, 'service1', 28]
);
the function who display and sort the array;


Code:
function buildMainMenu(_arr:Array) {

_arr.sort(0);

for (var i:Number = _arr.length-2; i>0; i--) {
for (j=0; j<=i; j++) {
if (_arr[j][0] != _arr[j+1][2] && _arr[j+1][2] != 1 && _arr[j+1][2] != 0) {
var num = _arr[j];
_arr[j] = _arr[j+1];
_arr[j+1] = num;
}
}
}

var parentItem = undefined;
var pK = 2;
var childItem = undefined;
var cK = 3;
var childschildItem = undefined;
var ccK = 4;
var childschildschildItem = undefined;
var cccK = 5;

for (var i:Number = 0; i<_arr.length; i++) {
trace (_arr[i]);
var mc = this.attachMovie('btn_mc', 'mcChild'+i, i);
if (_arr[i][2] == 0) {
mc._x = 10;
mc._y = 10+(mc._height*i);
parentItem = _arr[i][0];
} else if (_arr[i][2] == parentItem) {
mc._x = 10*pK;
mc._y = 10+(mc._height*i);
childItem = _arr[i][0];
} else if (_arr[i][2] == childItem) {
mc._x = 10*cK;
mc._y = 10+(mc._height*i);
childschildItem = _arr[i][0];
} else if (_arr[i][2] == childschildItem) {
mc._x = 10*ccK;
mc._y = 10+(mc._height*i);
childschildschildItem = _arr[i][0];
} else if (_arr[i][2] == childschildschildItem) {
mc._x = 10*cccK;
mc._y = 10+(mc._height*i);
}
mc.txt.text = _arr[i][1];
}
}

buildMainMenu(arr);
as you can se this isnt working propertly and the code is quite complex.. and my mind is big enouge to find a work around for this.. heeelp

tanx

Hans Philip

seems to work fine afterall

Help Witih Multidimensional Array
at the top i declare the array:


Code:
var songData = new Array();
Now i populate the array in a function

Code:
..for..
this.songData[i]['id'] = resource.attributes.url;
this.songData[i]['art'] = "asdas";
I finally call the array and try and access it

Code:
ID = 10; //example index
lbl_artist.text = this.songData[ID]['id'];
lbl_song.text = this.songData[ID]['art'];
i get nothing when i try accessing the index like above... it wont let me access the array via specifying my own index, i.e
this.songData[10]['id'];

any ideas?
flash8 and i checked Actionscript 2.0
thanks

Multidimensional Array Not Working
I am trying to grab some rss data, put into array, then use values in array in a ticker.

The part that I can't get to work is my arWeather array in the processBook function. Keeps giving me undefined. Any thoughts on why?



Code:
tuteInfo_xml = new XML();
tuteInfo_xml.ignoreWhite = true;
var iCnt:Number;
var arWeather:Array = new Array();
iCnt = 0;


tuteInfo_xml.onLoad = function (success) {
if (success) {
//trace('rss loaded. Contents are: '+this.toString());
processBook(tuteInfo_xml);

/*trace(arWeather.length);
for(var i in arWeather){
for(var j in arWeather[i]){
trace(j + ": " + arWeather[i][j]);
}
}
*/
}
}

tuteInfo_xml.load('http://www.weather.gov/alerts/us.rss');

function processBook(tuteInfo_xml) {
// tuteInfo_xml is now a reference to the XML
// object where our information is stored
for (item in tuteInfo_xml.childNodes[0].childNodes[0].childNodes) {
//trace(tuteInfo_xml.childNodes[0].childNodes[0].childNodes[item].nodeName);
if (iCnt < 6) {
if (tuteInfo_xml.childNodes[0].childNodes[0].childNodes[item].nodeName == "item") {
for (nItem in tuteInfo_xml.childNodes[0].childNodes[0].childNodes[item].childNodes) {
if (tuteInfo_xml.childNodes[0].childNodes[0].childNodes[item].childNodes[nItem].nodeName == "title"){
arWeather[iCnt] = new Array();
arWeather[iCnt][0] = tuteInfo_xml.childNodes[0].childNodes[0].childNodes[item].childNodes[nItem].firstChild.nodeValue;
//trace(tuteInfo_xml.childNodes[0].childNodes[0].childNodes[item].childNodes[nItem].firstChild.nodeValue);
trace (arWeather[iCnt][0]);
}
if (tuteInfo_xml.childNodes[0].childNodes[0].childNodes[item].childNodes[nItem].nodeName == "link"){
arWeather[iCnt][1] = tuteInfo_xml.childNodes[0].childNodes[0].childNodes[item].childNodes[nItem].firstChild.nodeValue;
trace (arWeather[iCnt][1]);
iCnt++;
}
}
}
}
//arWeather[0] = new weatherlink("abc", "xyz");
}
}

_root.onEnterFrame = function()
{
var dx:Number;
var dy:Number;
dx = _xmouse - mcBox._x;
dy = _ymouse - mcBox._y;
var angle:Number;
var newAngle:Number;
angle = Math.atan2(dy, dx);
newAngle = angle * 180 / Math.PI
_root.mcBox._rotation = newAngle;
//trace(_root.txtHW._x);
if (_root.txtHW._x > Stage.width) {
_root.txtHW._x = 100;
_root.txtHW.Text = "Lee's test2";
} else {
_root.txtHW._x = _root.txtHW._x + 10;
}

}


// Object constructor
function weatherlink(title, url) {
this.title = title;
this.url = url;
}

Problem With Multidimensional Array
I need to fill a two-dimensional array like this:


Code:
myweek = new Array();
myweek[1,0] = "Monday";
myweek[1,1] = "Tuesday";
myweek[1,2] = "Wednesday";
myweek[1,3] = "Friday";
myweek[1,4] = "Thursday";
myweek[1,5] = "Saturday";
myweek[1,6] = "Sunday";
myweek[2,0] = "222Monday";
myweek[2,1] = "222Tuesday";
myweek[2,2] = "222Wednesday";
myweek[2,3] = "222Friday";
myweek[2,4] = "222Thursday";
myweek[2,5] = "222Saturday";
myweek[2,6] = "222Sunday";
But when I search the element [1,6] with:

Code:
trace(myweek[1,6]);
I obtain: 222Sunday and not Sunday (the very correct result).

What's wrong? Help me please!

Using Push With A Multidimensional Array
I've made a multidimensional array which has three dimensions

I now am trying to us the push function to add elements to the three arrays..


ActionScript Code:
_parent.basketArray[0].push(item_codeV);
    _parent.basketArray[1].push(heading_1TXT);
    _parent.basketArray[2].push(price);

    trace(_parent.basketArray[0][0]);

but the trace is coming back as undefined

XML Data Into A Multidimensional Array
I need to create a 2-dimensional array on the fly. I've successfully loaded the XML file.

Here's an example of the xml:

PHP Code:



<menu name="example">
    <menu name="Van Halen">
        <item name="Eddie" />
        <item name="Sammy" />
        <item name="Alex" />
    </menu>
    <menu name="Police">
        <item name="Sting" />
        <item name="Andy" />
        <item name="Stew" />
    </menu>
    <menu name="Yankees">
        <item name="Williams" />
        <item name="Sheffield" />
        <item name="Matsui" />
    </menu>
    <item name="Aerosmith" />
    <item name="Jets" />
</menu> 




Here's my code:

PHP Code:



for (var i = 0; i < menu_xml.firstChild.childNodes.length; i++) 
{        
    for(var x = 0; x < menu_xml.firstChild.childNodes[i].childNodes.length; x++)
    {
        curr_node = menu_xml.firstChild.childNodes[i];
        baby_node = menu_xml.firstChild.childNodes[i].childNodes[x];
        aMenuList[i][x] = [curr_node.attributes.name, baby_node.attributes.name];
    }





This is the last derivation of many other attempts at getting this data parsed into an array. Please help!!!

Thanks!

Defining Multidimensional Array HELP
i want create an array to store the following...



[[ [character1], [[eyes,loc_eyesx,loc_eyesy],[mouth,loc_mouthx,loc_mouthy] ] ,
[ [character2] , [[eyes2,loc_eyesx,loc_eyesy], [mouth,loc_mouth2x,loc_mouth2y ] ] ]

....first entry is name of the character and then after that they are arrays that store the specifications pf that character ..
basically i am trying to redraw character by storing the body part name and the locations

can this be done and how do i define such an array??


thanks

Multidimensional Associative Array
Hi,
This is my first post in these forums and I greet you all!

I would like to create a multidimensional associative array so that I can refer to items using two keys i.e.:
aChessBoard["A"]["5"] = "Knight";
aChessBoard["A"]["3"] = null;
aChessBoard["B"]["5"] = "Bishop";

I have already tried


but this does not print anything. Any suggestions?







Attach Code

var _aBoard:Object;
_aBoard["A"]["1"] = "N";
_aBoard["A"]["2"] = "o";

for (var sKey:String in _aBoard) {
trace("KEY = " + sKey );
for (var sKey2:String in _aBoard[sKey]) {
trace(" KEY 2 = " + sKey2 + "ITEM = " + _aBoard[sKey][sKey2]);
}
}

Copyright © 2005-08 www.BigResource.com, All rights reserved