Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><code>addChild</code> adds items to the top of the display list, so when you are adding your ellipses to the stage, you are adding them in front of your button and movie. That is, your movie (with the button) is at index 0, but your shapes are added at index 1 and higher. One solution would be to add them below the movie instead, using <code>addChildAt</code>:</p> <pre><code>var shapeIndex:uint = 0; function makeShapes(e:MouseEvent):void { var ellipse:Ellipse = new Ellipse(10, 10, color); stage.addChildAt(ellipse, shapeIndex); // add the shape starting at 0, and count up from there // this will keep the movie at the top of the stage's display list shapeIndex++; ellipse.x = mouseX; ellipse.y = mouseY; } </code></pre> <p>An alternative solution is to first make a container clip, and then add the shape's to this container clip instead. This allows you to easily control where the shapes appear:</p> <pre><code>var container : Sprite = new Sprite(); stage.addChildAt(container, 0); // add the container to the bottom of the stage // now we can just easily add our shapes to the container, and they will all be behind the main movie. function makeShapes(e:MouseEvent):void { var ellipse:Ellipse = new Ellipse(10, 10, color); container.addChild(ellipse); shapeIndex++; ellipse.x = mouseX; ellipse.y = mouseY; } </code></pre> <p>And this actually makes other things such as clearing your screen easier. You can simply remove and recreate the container clip:</p> <pre><code>function clearBoard(e:MouseEvent) { stage.removeChild(container); container = new Sprite(); stage.addChildAt(container, 0); } </code></pre>
 

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