I have an array defined in the main timeline to store some values. At some point of time, I am dynamically adding a movieclip to stage using attachMovie and then using a movieClip.onEnterFrame event to set one of its values by referencing to one value from the main array.
(Sorry if the following description sounds a bit confusing. I am attaching a part of the code below to help describe the situation) The problem is that it is not able to retrieve the value from the main array no matter what I try. I tried adding a “_root” befor the array name and the index array id but it did not work. Not only that but the trace shows that it is able to retrieve the index id as well as the full array but not any particular value from the array - as in, trace(arrayname) outputs all the values from that array but trace(arrayname[a]**[c]) gives an output ‘undefined’.
I have managed to make it work by creating a temporary variable to store that particular value just before the onEnterFrame event kicks in, but I would love to know why it is not working the way I thought it should. Here is a part of the code. If someone needs more info about the code then please ask and I will give it in the next post (The full code is way too large to be posted here)
ActionScript Code:
[FONT=Courier New][LEFT][COLOR=#808080]*//------In main timeline *[/COLOR]
[COLOR=#000000]var[/COLOR] movesNum:[COLOR=#0000ff]Number[/COLOR] = [COLOR=#000080]0[/COLOR];
[COLOR=#000000]var[/COLOR] movesArray:[COLOR=#0000ff]Array[/COLOR] = [COLOR=#000000]new[/COLOR] [COLOR=#0000ff]Array[/COLOR]COLOR=#000000[/COLOR];
[COLOR=#000000]var[/COLOR] capturesArray:[COLOR=#0000ff]Array[/COLOR] = [COLOR=#000000]new[/COLOR] [COLOR=#0000ff]Array[/COLOR]COLOR=#000000[/COLOR];
[COLOR=#000000]var[/COLOR] castleArray:[COLOR=#0000ff]Array[/COLOR] = [COLOR=#000000]new[/COLOR] [COLOR=#0000ff]Array[/COLOR]COLOR=#000000[/COLOR];
castleArray[COLOR=#000000][[/COLOR][COLOR=#000080]0[/COLOR][COLOR=#000000]][/COLOR] = [COLOR=#000000]new[/COLOR] [COLOR=#0000ff]Array[/COLOR]COLOR=#000000[/COLOR];
castleArray[COLOR=#000000][[/COLOR][COLOR=#000080]1[/COLOR][COLOR=#000000]][/COLOR] = [COLOR=#000000]new[/COLOR] [COLOR=#0000ff]Array[/COLOR]COLOR=#000000[/COLOR];
capturesArray[COLOR=#000000][[/COLOR][COLOR=#000080]0[/COLOR][COLOR=#000000]][/COLOR] = [COLOR=#000000]new[/COLOR] [COLOR=#0000ff]Array[/COLOR]COLOR=#000000[/COLOR];
capturesArray[COLOR=#000000][[/COLOR][COLOR=#000080]1[/COLOR][COLOR=#000000]][/COLOR] = [COLOR=#000000]new[/COLOR] [COLOR=#0000ff]Array[/COLOR]COLOR=#000000[/COLOR];
capturesArray[COLOR=#000000][[/COLOR][COLOR=#000080]2[/COLOR][COLOR=#000000]][/COLOR] = [COLOR=#000000]new[/COLOR] [COLOR=#0000ff]Array[/COLOR]COLOR=#000000[/COLOR];
movesArray[COLOR=#000000][[/COLOR][COLOR=#000080]0[/COLOR][COLOR=#000000]][/COLOR] = [COLOR=#000000]new[/COLOR] [COLOR=#0000ff]Array[/COLOR]COLOR=#000000[/COLOR];
movesArray[COLOR=#000000][[/COLOR][COLOR=#000080]1[/COLOR][COLOR=#000000]][/COLOR] = [COLOR=#000000]new[/COLOR] [COLOR=#0000ff]Array[/COLOR]COLOR=#000000[/COLOR];
movesArray[COLOR=#000000][[/COLOR][COLOR=#000080]2[/COLOR][COLOR=#000000]][/COLOR] = [COLOR=#000000]new[/COLOR] [COLOR=#0000ff]Array[/COLOR]COLOR=#000000[/COLOR];
movesArray[COLOR=#000000][[/COLOR][COLOR=#000080]3[/COLOR][COLOR=#000000]][/COLOR] = [COLOR=#000000]new[/COLOR] [COLOR=#0000ff]Array[/COLOR]COLOR=#000000[/COLOR];
movesArray[COLOR=#000000][[/COLOR][COLOR=#000080]4[/COLOR][COLOR=#000000]][/COLOR] = [COLOR=#000000]new[/COLOR] [COLOR=#0000ff]Array[/COLOR]COLOR=#000000[/COLOR];
movesArray[COLOR=#000000][[/COLOR][COLOR=#000080]5[/COLOR][COLOR=#000000]][/COLOR] = capturesArray;
movesArray[COLOR=#000000][[/COLOR][COLOR=#000080]6[/COLOR][COLOR=#000000]][/COLOR] = castleArray;
[COLOR=#0000ff]this[/COLOR].[COLOR=#0000ff]attachMovie[/COLOR]COLOR=#000000[/COLOR];
[COLOR=#000000]var[/COLOR] capPos:[COLOR=#0000ff]Number[/COLOR] = movesArray[COLOR=#000000][[/COLOR][COLOR=#000080]5[/COLOR][COLOR=#000000]][/COLOR][COLOR=#000000][[/COLOR][COLOR=#000080]1[/COLOR][COLOR=#000000]][/COLOR][COLOR=#000000][[/COLOR]movesNum[COLOR=#000000]][/COLOR]; [COLOR=#808080]//<-- THIS WORKS[/COLOR]
[COLOR=#0000ff]this[/COLOR][COLOR=#000000][[/COLOR]movesArray[COLOR=#000000][[/COLOR][COLOR=#000080]5[/COLOR][COLOR=#000000]][/COLOR][COLOR=#000000][[/COLOR][COLOR=#000080]0[/COLOR][COLOR=#000000]][/COLOR][COLOR=#000000][[/COLOR]movesNum[COLOR=#000000]][/COLOR][COLOR=#000000]][/COLOR].[COLOR=#0000ff]onEnterFrame[/COLOR] = [COLOR=#000000]function[/COLOR] COLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#808080]// this.currPos = movesArray[5][1][movesNum];[/COLOR]
[COLOR=#808080]// this.currPos = _root.movesArray[5][1][movesNum];[/COLOR]
[COLOR=#808080]// this.currPos = _root.movesArray[5][1][_root.movesNum];[/COLOR]
[COLOR=#808080]//NONE OF THE ABOVE WORK EVEN THOUGH “trace(movesNum)” and “trace(movesArray)” GIVE CORRECT OUTPUT. BUT "trace(movesArray[5][1][movesNum]) OUTPUTS “undefined”[/COLOR]
[COLOR=#0000ff]this[/COLOR].[COLOR=#000080]currPos[/COLOR] = capPos; [COLOR=#808080]*//<--- THIS WORKS*[/COLOR]
[COLOR=#0000ff]delete[/COLOR] [COLOR=#0000ff]this[/COLOR].[COLOR=#0000ff]onEnterFrame[/COLOR];
[COLOR=#000000]}[/COLOR]
[COLOR=#808080]//-------Inside the movieclip attached----[/COLOR]
[COLOR=#000000]var[/COLOR] currPos:[COLOR=#0000ff]Number[/COLOR];
[/LEFT]
[/FONT]
Can someone please help me understand what I am doing wrong with the referencing here. :puzzled:
Thanks a lot.