Copy link to clipboard
Copied
It is not supposed that if the length of an array is, eg,
var myArray:int = new Array();
myArray = 10;
if the setted legth(myArray = 10) is ten, why is the length one more than its last index, ie, 11.
?
Copy link to clipboard
Copied
Array indexes start at 0. That is how arays have been defined pretty much since they ever came into being, long before Actionscript existed. The first item in an array occupies the 0 index slot. The length of an array tells you the number of items the array contains.
As for the rest of your posting it doesn't make sense as a question nor as code. If you are defining myArray as an int, you cannot have it assigned to an Array
Copy link to clipboard
Copied
So
var myArray:array = new Array();
myArray.push(10);
if length = 10, why is the length one more than the last index, so if length is 10 it really is 11.
Copy link to clipboard
Copied
I have no clue what you are trying to say. Your code is still incorrect because there is no "array" class... it is spelled with a capital letter "Array"
Even if you correctly defined the array, all your code did was push 1 value into the array, so it's length is 1 at that point. Try using code to work thing out, maybe using the trace function will help you in that regard...
var myArray:Array = new Array();
myArray.push(10);
trace(myArray); // will display what is in the array
trace(myArray.length); // will tell you how many items are in the array
If you want to define an array with a length of 10 you can use ....
var myArray:Array = new Array(10);
trace(myArray); // will display what is in the array
trace(myArray.length); // will tell you how many items are in the array
Notice the difference in what displays for the two different cases.
If the length is 10, the index of the 10th item is 9. I don't know how you reasoned 11 into that or what "it" is that would be 11. I already explained that the indexes start at 0 and the length indiocates the number of items in the array.
You should probably work with arrays to get used to how they are defined and how they work.
Copy link to clipboard
Copied
Let me see if I understood, if length is ten, its last index is 9, and if the array legth is one more than its last index, ie 9(the last index) plus 1 will be equal to 10, ie, the array legth.
am I right?
Copy link to clipboard
Copied
You're really complicating this. Arrays have 0 based indexes, that's all there is to it. If you have an array with 1 item in it the length is 1 and it's at index 0. That's why when you iterate with say a for loop you start at 0 and you check that the index is less than the length like so:
var a:Array = [1,2,3,4,5];
for(var i:int = 0; i < a.length; i++){
trace(a);
}
Copy link to clipboard
Copied
Okay, now I understood, You can set this question as answered, thank you guys.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now