# [F5] [FMX]  Array Manipulation

I have been researching this Array manipulation for 3 days and nights now, and to no avail for what I have been after, except in a small way with the slice() function . . .

I have an Array of 16 cards, named Alpha, Bravo . . . Osca, Papa.
In a loop that will execute 16 times I want one single card to be read from the array at a random point, but, on each cycle, remove the card that has been chosen.

So far I have come up with this psuedo, bare with me.

``````
/// Variable Deffinition ///

var	\$x	: integer	/// x co-ordinate variable.
\$y	: integer	/// y co-ordinate variable.
\$card	: string	/// puzzle piece instance name.
\$hex	: integer	/// randomiser throw to reach the hexadecimal elements.
\$i	: integer	/// index for array calling.
\$i2	: integer	/// index + 1 for moving along array.

/// Array Deffinition /// 16 Elements from 0 - 15 /// A - P ///

\$piece new Array["Alpha", "Bravo", "Chalrie", "Delta", "Echo", "Foxtrot", "Golf",
"Hotel", "Indigo", "Juliet", "Kilo", "Lima", "Mike", "November",
"Osca", "Papa"]

\$x	= 480		/// first piece x co-ordinate value.
\$y	= 80		/// first piece y co-ordinate value.
\$hex	= 5		/// first value of the throw.

/// Start Loop ///

For 1-16 Do	/// For loop, 16 repititions of the loop.
{

\$i = (math.Round(math.Random() * 10) + \$hex)	/// sets index as a random number from 0 - 10 plus the hex throw
\$i2 = (\$i + 1)			/// sets index + 1
\$hex = (\$hex - 1)		/// throw -1 as array will lesen by 1

\$card = trace(\$piece[\$i])	/// sets \$card as the name pulled from the array
\$piece = \$piece.slice(\$i,\$i2)	/// sets piece array as piece array minus piece pulled

setProperty(\$card, _x, \$x)	/// sets x co-ordinate for random piece value \$x
setProperty(\$card, _y, \$y)	/// sets y co-ordinate for random piece value \$y

\$x = \$x + 80			/// moves one piece to the right

if \$x == 800 || \$x < 720	/// if \$x is equal to 800 or greater than 720 do this
{
\$x = 480		/// reset \$x back to 480, taking the piece to the left
\$y = \$y + 80		/// set \$y plus 80, taking piece to next row down
}
}

``````

The 16 cards will be in this formation
[] [] [] []
[] [] [] []
[] [] [] []
[] [] [] []
Hence the very slight variations with the co-ordinates. Each card is 80*80 pixels.

I was wondering if the

``````
\$card = trace(\$piece[\$i])
\$piece = \$piece.slice(\$i,\$i2)

``````

section would work. As I have not seen anyone try overplace an Array with an Array, and there doesn’t seem to be a way of removing elements from the middle of an Array, only the begining and the ends, which I find hardly practicle.

Or if the script in general is a pile of dung.

It has taken me a while to think of this method for placing the cards where I want them, instead of all over the screen, so I am a little exhausted, plus I am a little n00b with action script.

In short this is my psuedo code, I was wondering where does it need tweeking to work with a basic on(press) function, or would it work as is? (If it works at all)

Also will it work with Flash 5 or is slice a MX ++ function?

Last to ask, does anyone know of a more effective way to pull of the shuffle, because I am a bit on the iff with the

``````
\$hex = (\$hex - 1)

``````

section, because if my throw is at the -8 and the random number generated is 3, what will happen with the array and do I need some form of exception handler in there?

If I am goping the wrong way about this whole method . . . I would appreciate some suggestions of an alternative corse.