-
Don't understand my trace results
To my knowledge the 'push' command in an array will add one more item. Therefore why does the following script trace 2,4,6,8,10 instead of 1,2,3,4,5
code:
var array:Array = new Array();
for (i = 0; i < 10; i++)
{
targ = new en();
targ.x = Math.round(Math.random() * wi);
targ.y = Math.round(Math.random() * hi);
array.push(targ);
addChild(targ);
}
-
.
Hi,
It doesn't trace anything as there is no trace in there.
Post the code that you are using the trace in.
The code above even with a trace placed after the addChild(targ) like so trace(i);
traces 0 - 9
??
-
my apologies. It should have been:
trace(array.push(targ));
-
.
Hi,
Not entirely sure why you would want to trace that!
PHP Code:
var array:Array = new Array();
for (i = 0; i < 10; i++)
{
targ = new en();
targ.x = Math.round(Math.random() * wi);
targ.y = Math.round(Math.random() * hi);
array.push(targ);
addChild(targ);
trace(i);
}
trace("array of objects: " +array);
trace("targeted object: " + array[3].x);
-
.
Hi,
In answer to your trace, trace(array.push(targ)); I think it doesn't know what to do so traces the array length
Even when you use the array.push() within a trace it pushes the array,
hence the number being double the for (i = 0; i < 10; i++) amount
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
|