-
Member
Named array numbers
okay.. I know the easy way to avoid this but
If you have an array which has subarrays which have a string as the index (so for example MyArray["Apple"].price, MyArray["Bananna"].price etc) can the entries still be accessed as numbers? like if "Apple" was the first index in the array, then MyArray[0] would be the same as MyArray["Apple"]. I guess it would because surely it's flash that is converting it to allow a string as an index, so there is a number there.. but not sure.
-
Client Software Programmer
To find the index for apple you could do, trace(myArray.indexOf("Apple")); and you would get its array position is that what you need? if the index is not found you will get the value -1 so if myArray.indexOf("Pear")==-1 you would see there is no pear and you can myArray.push("Pear");
Last edited by AS3.0; 12-15-2016 at 10:28 AM.
-
Member
mmm.. forgot you could do that.. so that does seam to say that with names, they still have numbers.. so myArray[0] (if the index returns the same) is the same as myArray["Apple"]...
thanks
-
Client Software Programmer
No problem, if you enjoyed that script, feel free to buy me a doughnut, paypal: giancarlo.quarta@yahoo.com
Last edited by AS3.0; 12-15-2016 at 10:54 AM.
-
.
Hi,
The way you have your array looks more like an associative array (object array) hence the .price on each, I don't think they have a length attribute but you can loop though the props of associative arrays to get a count.
PHP Code:
var cnt:Number = 0;
for(var id:String in myArray)
{
cnt++;
var val:Object = myArray[id];
trace(cnt + " / " + id + " = " + val);
}
-
.
Hi,
Unless of course you are using multi dimensional arrays
PHP Code:
var myArray1:Array = new Array("Apple","Banana");
trace(myArray1["Apple"]); trace(myArray1[0]);
trace(myArray1.indexOf("Apple"));
trace("---------------------------");
var myArray2:Array = new Array(["Apple"],["Banana"]);
trace(myArray2["Apple"]); trace(myArray2[0]);
trace(myArray2.indexOf("Apple"));
notice the difference
-
Member
yeah, it's and associative array but it wasn't more about the total length but the index of each element. thanks though
-
.
Hi,
Then i believe you need to reference them each by name.
-
Client Software Programmer
http://www.TESP.co.uk looking nice Manic did you make the site, has a few graphic glitches when minimized abit though
-
.
Hi,
whatever happened to your site Alloy, it's good to have showcase of your own as well as having the google play area, I think people take you a little bit more serious if you have at least a home page.
-
Client Software Programmer
its good its running on IIS 7.5 it wont be online for a while
-
yes, nice Tesp. sega creature good.
sorry not help with coded
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|