A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Don't understand my trace results

  1. #1
    Member
    Join Date
    Apr 2014
    Posts
    63

    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);

    }


  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    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

    ??

  3. #3
    Member
    Join Date
    Apr 2014
    Posts
    63
    my apologies. It should have been:

    trace(array.push(targ));

  4. #4
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Not entirely sure why you would want to trace that!

    PHP Code:
    var array:Array = new Array(); 

    for (
    010i++) 

        
    targ = new en(); 
        
    targ.Math.round(Math.random() * wi); 
        
    targ.Math.round(Math.random() * hi); 
        array.
    push(targ); 
        
    addChild(targ); 
        
    trace(i);


    trace("array of objects: " +array);
    trace("targeted object: " + array[3].x); 

  5. #5
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center