Lui
09-06-2006, 10:11 PM
Wipee! My Array tutorial is finally here. This tutorial is now to run
you through the basics of arrays, just like my variables tutorial.
Arrays are very much alike variables, they do the almost the same thing
but arrays contain variables. So you may use arrays to store multiple
variables instead of having billions of variables running through your
codes.
Arrays are basically set up like this:
myarray = new Array();
That won't do much for us though, we want to store or data.
First we would have to set them up with the data.
They can be set up in many different ways.
One of them is
myarray = new Array("data1", "data2", "data3");
The one above could also be set up as
myarray = new Array();
myarray[0] = "data1";
myarray[1] = "data2";
myarray[2] = "data3";
It doesn't matter which way you do it, you will get the same outcome if
you correctly did both. Now lets try and call up our datas
myarray = new Array();
myarray[0] = "data1";
myarray[1] = "data2";
myarray[2] = "data3";
trace (myarray[1]);
Test the movie and the code should trace number 2 in our array.
Remmember that it doesn't always need to be text it can also be numbers!
Also, that when calling arrays, the values always start from 0. e.g
myarray[0], myarray[2], myarray[3] etc...
And you can also store other variables in an array by just taking the
(")s off.
myarray = new Array();
myarray[0] = variable1;
myarray[1] = variable2;
myarray[2] = variable3;
trace (myarray[1]);
To display array contents on a dynamic text field just place the name of your array on the "var" part. It will show all content in the array, but if you want to show only one I suggest you do something like this:
text1 = myarray[1];
This will set text1 (which is the variable we are going to use to show our content on the textfield) to whatever myarray[1]'s content is.
Challenge
---
Try displaying all of your array's content on one textfield and displaying every each and one of its contents. It will take time, but it will prove that you have learned how to use arrays. Another thing to try out is to contain variables in an array then display it.
---
If you do fail to do this challenge, I suggest you read through my tutorial again. I hope this tutorial was usefull!
LuiV
P.S I'm a duck!
you through the basics of arrays, just like my variables tutorial.
Arrays are very much alike variables, they do the almost the same thing
but arrays contain variables. So you may use arrays to store multiple
variables instead of having billions of variables running through your
codes.
Arrays are basically set up like this:
myarray = new Array();
That won't do much for us though, we want to store or data.
First we would have to set them up with the data.
They can be set up in many different ways.
One of them is
myarray = new Array("data1", "data2", "data3");
The one above could also be set up as
myarray = new Array();
myarray[0] = "data1";
myarray[1] = "data2";
myarray[2] = "data3";
It doesn't matter which way you do it, you will get the same outcome if
you correctly did both. Now lets try and call up our datas
myarray = new Array();
myarray[0] = "data1";
myarray[1] = "data2";
myarray[2] = "data3";
trace (myarray[1]);
Test the movie and the code should trace number 2 in our array.
Remmember that it doesn't always need to be text it can also be numbers!
Also, that when calling arrays, the values always start from 0. e.g
myarray[0], myarray[2], myarray[3] etc...
And you can also store other variables in an array by just taking the
(")s off.
myarray = new Array();
myarray[0] = variable1;
myarray[1] = variable2;
myarray[2] = variable3;
trace (myarray[1]);
To display array contents on a dynamic text field just place the name of your array on the "var" part. It will show all content in the array, but if you want to show only one I suggest you do something like this:
text1 = myarray[1];
This will set text1 (which is the variable we are going to use to show our content on the textfield) to whatever myarray[1]'s content is.
Challenge
---
Try displaying all of your array's content on one textfield and displaying every each and one of its contents. It will take time, but it will prove that you have learned how to use arrays. Another thing to try out is to contain variables in an array then display it.
---
If you do fail to do this challenge, I suggest you read through my tutorial again. I hope this tutorial was usefull!
LuiV
P.S I'm a duck!