Noob Flash Rss

Creating a Multidimensional Array in Flash

8

Posted by Aaron | Posted in ActionScript | Posted on 14-04-2007

With a typical Array in Flash, you can define one element and call that element with the arrayName[arrayIndex]. This works fine if you only have one element you want to be defined in the array. What if you want to define multiple elements in the array? That’s where multidimensional arrays come into play.

Here is an example of multidimensional array code in flash.

var array:Array = new Array();
array[0] = ["cat.jpg", "1", "Here is a picture of a cat"];
array[1] = ["dog.jpg", "2", "Here is a picture of a dog"];
array[2] = ["frog.jpg", "3", "Here is a picture of a frog"];

To access the data, use array[0][0] to access “cat.jpg”, array[1][1] to access “2″, and array[2][2] to access “Here is a picture of a frog”.

Related posts:

  1. Load XML in Flash (AS3)
  2. Basic JavaScript Array Tutorial

Comments (8)

Thank you. This is the only explanation I could find (websites, books) that explained what I was trying to do with the array.

good

Thanks!

I am using arrays like this in AS3, but I keep getting errors??

/* EXAMPLE-CHANNELS */
var chans = new Array();//[title,ip:port;stream.nsv,description]
var chans[0] = ["Radio #1", "http://s2.viastreaming.net:7130;stream.nsv", "Latest hits.\nhttp://www.radio1.com"];
var chans[1] = ["Classics", "http://193.112.14.122:8080;stream.nsv", "Classical music 24/7.\nhttp://www.classicradio.com"];
var chans[2] = ["FunkRadio", "http://stream.funkradio.com:7130;stream.nsv", "Funk music!.\nVisit http://www.funkradio.com"];
/* END OF CHANNEL-ARRAY */

Whats the problem?
1086: Syntax error: expecting semicolon before leftbracket.

Nice

Thanks Noob!

@doug:
Don’t put “var” before chans[0],chans[1],chans[2].

@doug: It contains quite a few bugs

Post a comment