-
[F8] arrays
Hello,
I've created a new array called "space"
Code:
space = new Array()
and assigned a button to add values to it
Code:
on(press){
spaced = space.push(8)
}trace(space)
the trace becomes something like "8,8,8,8"
How do I convert the data in an array into numeric data? I intend to use the "8" in a calculation.
thanks. I hope my question is clear enough.
-
Hi soony, I suppose your problem is the way you extract your element from the array.
I mean when you push the button you add the 8 to your array, that 8 will occupy position0 into your array, if you push again the button you'll add another 8 to your array that will occupy position1 (if you trace space you will get: '8,8')
Now suppose that you want to add the first two elements of your array, that means that you're going to add position0 to position1, so it would be
var addition:Number = space[0]+space[1]; -> (result will be 16)
Or suppose that you want add position0 to say 10, it will be
var addition:Number = space[0]+10; -> (result will be 18)
So basically when you extract the element from your array, you'll have to specify what postion it occupies within the array.
Hope that helps
Good luck
Giano
-
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
|