Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Looks like you could probably add <code>v</code> to the display list, rather than <code>container[i]</code>. Have you tried that?</p> <p>UPDATE: Actually, I think the problem comes from the second item in your loop definition. It should be <code>i &lt; allElements.length</code>, rather than <code>allElements.length</code>. The way you've got it set up, it is running one time more than it should.</p> <p>Below is some working code, based on what you posted, above. Hit me with a comment if I need to clarify (anyone - been a rough morning, so far...).</p> <pre><code>var el1_spr:Sprite = new Sprite; var el2_spr:Sprite = new Sprite; var el3_spr:Sprite = new Sprite; el1_spr.graphics.beginFill(0x0000FF); el1_spr.graphics.moveTo(0,0); el1_spr.graphics.lineTo(100,0); el1_spr.graphics.lineTo(100,100); el1_spr.graphics.lineTo(0,100); el1_spr.graphics.lineTo(0,0); el1_spr.graphics.endFill(); el2_spr.graphics.beginFill(0x00FF00); el2_spr.graphics.moveTo(0,0); el2_spr.graphics.lineTo(100,0); el2_spr.graphics.lineTo(100,100); el2_spr.graphics.lineTo(0,100); el2_spr.graphics.lineTo(0,0); el2_spr.graphics.endFill(); el3_spr.graphics.beginFill(0xFF0000); el3_spr.graphics.moveTo(0,0); el3_spr.graphics.lineTo(100,0); el3_spr.graphics.lineTo(100,100); el3_spr.graphics.lineTo(0,100); el3_spr.graphics.lineTo(0,0); el3_spr.graphics.endFill(); var elements:Array = new Array (el1_spr, el2_spr, el3_spr); var container:Array = new Array(); for (var i:uint; i &lt; elements.length; i++) { container.push(elements[i]); var v:Sprite = (elements[i] as Sprite); addChild(v); //addChild(elements[i]); // this also works //addChild(container[i]); // this also works v.x += (100 * i); //elements[i].x += (100 * i); // this also works //container[i].x += (100 * i); // this also works } </code></pre> <p>I don't know what the context of your code is, but for what it might be worth, I included a couple of extra lines to show that you don't necessarily need the <code>container</code> Array, or to create <code>v</code>.</p> <p>Hope that's helpful.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload