To add a value in the MIDDLE of an array, you need to specify your insertion point and a delete count.
This is a little more complex, and follows this format: array.splice(Insertion point, Delete Count, Value to insert)
If you don't wish to delete a value when splicing, just use '0' for the Delete Count

To sort the contents of an array alphabetically or numerically, you can use array.sort() or array.sortOn.
There are various optional parameters you can use when sorting an array... since I'm trying to keep this post reasonable simple, I'll refer you to the official pages: sort - sortOn

-------------------------------------------------

There are a couple of array functions I haven't covered (concat and toString). For more information on arrays, check out these links:

Here are some custom methods for arrays than can be useful. If you haven't worked with object prototypes before, just have in mind to put this code anywhere prior to the frame/mc... where they are used.

Array.has(Element)
Description: returns a Boolean value indicating if array has or not the Element specified.
Code:

This kind of array could be used to store a tile map for an RPG, just have a code in the tile that refers to the array and displays the right tile depending on your position. To get a value from a nested array is easy, you just need to use extra square brackets:

tile.gotoAndStop(myMap[y_co][x_co]+1);

The value in the first set of square brackets direct the script to an element within the 'myMap' array, if it were a numeric or text variable, that would be enough, but as it is another array we would need another set of brackets to reach something usable, so the second set of brackets direct a script to an element in the secondary array specified by the first set of brackets.

In the example, 'y_co' and 'x_co' variables represent the player's map co-ordinates, so if it were to be applied to a tile MC with different terrain graphics on each of it's frames, this code would make sure that the tile the player is standing on displays the correct terrain type.

You can have as many nested arrays as you need, I've never gone above 3 levels of nesting because It can get confusing and hard to manage, but it's useful for tile maps.

I've read the whole tutorial but it doesn't really teach how to use them.
For example using arrays for inventory, how can I do that?
Is it something like this?
inventory = new Array("sword","knife","potion","dagger","b
ow","arrows");

At 11/17/05 02:22 PM, glompho wrote:
can someone do a more indepth explanation of this or is there one?

nested arrays are arrays INSIDE arrays. you can use them for 3d rendering, or just for storing array information within an array. you can create them with the new Array(); command:var nest:Array = new Array([0, 1, 0], [1, 0, 0], [1, 1, 1]);

Using a loop to empty an array is useful when you have objects in it. It avoids memory leaks (crap objects staying in memory). Had the issue with Flash 7, though there may have been improvements to garbage collection in Flash 8.

Here is a good example of Arrays put to good use. Here is a quick flashcard program I made in flash, while I Was too damn lazy to make sure that it doesnt choose a random answer that is the real answer, it still gets the job done.

I've bene having difficulty with arrays. For some reason, putting an array variable (e.g. weapons[0]) into a dynamic text box variable box won't show it. If this is true always, is there a way of manipulating the array so I can grab any part of it for use in a dynamic text box.

I'm back! on a temporary basis. No-one can remember who I am! but I don't really mind.

At 11/19/05 09:09 AM, Devenger wrote:
I've bene having difficulty with arrays. For some reason, putting an array variable (e.g. weapons[0]) into a dynamic text box variable box won't show it. If this is true always, is there a way of manipulating the array so I can grab any part of it for use in a dynamic text box.

Just give the textbox an instance name (i.e. showArrayVar) then on the frame:

I've noticed the same problem in the past. I found the simpliest way to work around it was to create a variable of type string that always contained the information for the text box and then changed that variable to match the part of the array you wanted to display. Example:

That's the way I've started doing it. Athought it is a bit of a laborious process, because I have various dyn. text boxes, which reference data in a _root array about the names of various weapons, and clicking them brings up other details from the same array.

Still, I better get to it. ^-^

I'm back! on a temporary basis. No-one can remember who I am! but I don't really mind.