5 Replies Latest reply on Sep 27, 2010 7:50 AM by Radu Cristian Dimitrie

# Complex Names

maybe there might have been a discussion just like this, but i don't even know how ot search the internet..

Pseudocode:

var array1;

var array2;

var array3;

case 1:

myFunction(1);

case 2:

myFunction(2);

case 3:

myFunction(3);

function myFunction(myNumber)

{

a = ["array"+myNumber];

b = ["array"+(myNumber+1)];

trace(a) //output is array1 but is not the array1 that i declared, it's only a string

}

How do i point it to the array i want?

• ###### 1. Re: Complex Names

Solved

It needed a source to get the arrays from..

var array1 = [1,2,3];

var array2 = [2,3,4];

var array3 = [4,5,6];

case 1:

myFunction(1, this);

case 2:

myFunction(2, this);

case 3:

myFunction(3, this);

function myFunction(myNumber, from)

{

a = from["array"+myNumber];

b = from["array"+(myNumber+1)];

trace(a) // output is:  1,2,3

trace(b) // output is:  2,3,4

}

• ###### 2. Re: Complex Names

use array notation to coerce flash to convert strings as objects:

var tl:MovieClip = this

function myFunction(myNumber)

{

var a:Array = tl["array"+myNumber];

var b:Array = tl["array"+(myNumber+1)];

trace(a);

}

• ###### 3. Re: Complex Names

you'll need to be careful about the location of your function calls if you use your code.  you can easily be out of scope of the timeline where your arrays are defined.

it's better to use the code i suggested.

• ###### 4. Re: Complex Names

what this does, or at least should do, is return an array of neighbouring tiles from the unit's location depending on it's moving points..

the pseudo code:

if moving points > 1 { get neighbours and put them in array1}

if moving points > 2 { get neighbours for each element in array1, and put them in array2 and final array} (calls function 'getNextRange')

if moving points > 3 { get neighbours for each element in array2, and put them in array3 and final array} (calls function 'getNextRange')

......

`function getRange(from) //from is the soldier{     rangeArray1 = new Array();     rangeArray2 = new Array();     rangeArray3 = new Array();     rangeArray4 = new Array();     rangeArray5 = new Array();     rangeArrayF = new Array();     range = from.MP; //Mp = moving points     place = from.place; //place = the tile that the unit is standing on     if (range > 0)     {          range1 = _root.getNeighbours(place);          for (i = 0; i < 6; i++)          {               rangeArray1.push(range1[i]);               rangeArrayF.push(range1[i]);          }     }     if (range > 1)     {             getNextRange(1, this);     }        if (range > 2)        {             getNextRange(2);        }//      if (range > 3)//     {//          getNextRange(3);//     }//     if (range > 4)//     {//          getNextRange(4);//     }     function getNextRange(no, from)     {          a = from["rangeArray" + 1];          b = from["rangeArray" + (no+1)];          for (i = 0; i < a.length; i++)          {                         b.push(a[i]);               for (j = 0; j < 7; j++)               {                    b.push(_root.getNeighbours(a[i][j]));                    rangeArrayF.push(_root.getNeighbours(a[i][j]));               }          }                    b = b.getUniqueValues();     }     Array.prototype.getUniqueValues = function() //returns array without duplicates     {           ###################     }     rangeArrayF = rangeArrayF.getUniqueValues();     return rangeArrayF;}`

function getNeighbours returns an array of 6 elements, because it's a hexagonal tiled game, so i need to loop trough each 0 > 5 index element to push it to other array..

although it identifies the arrays a and b in the getNextRange function, there something messed up i need to find and fix, because function doesn't return what it should..

• ###### 5. Re: Complex Names

i solved the function getNextRange..

i misplaced the 'j':

b.push(_root.getNeighbours( a[i][j]) ); is wrong

b.push(_root.getNeighbours( a[i])[j] ); is correct

if you have any other suggestions i welcome them