Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding Sprites to Canvas in Flex
    primarykey
    data
    text
    <p>As requested, I'm giving a more detailed description of the problem...</p> <p>First off I have this MXML:</p> <pre><code>&lt;mx:Panel x="270" y="10" width="690" height="680" id="mainContainerPanel"&gt; &lt;mx:Canvas x="270" y="10" width="670" height="640" id="canvas" initialize="onInit()"&gt; &lt;mx:Script&gt; protected function onInit():void { spiro = new Spirograph(canvas); } &lt;/mx:Script&gt; &lt;/mx:Canvas&gt; &lt;/mx:Panel&gt; </code></pre> <p>This passes the tag object to the constructor of my main AS3 class file. This works fine, where in the constructor I have: </p> <pre><code>function Spirograph(canvas:Canvas):void { mainContainer = canvas; mainContainer.graphics.beginFill(0xFFFFFF); mainContainer.graphics.drawRect(0, 0, 670, 640); mainContainer.graphics.endFill(); } </code></pre> <p>At the moment, I am adding all Sprite objects to the mainContainer by using a wrapper class called SpriteUIContainer:</p> <pre><code>package includes { import flash.display.Sprite; import mx.core.UIComponent; public class SpriteUIContainer extends UIComponent { public function SpriteUIContainer(sprite:Sprite) { super(); this.explicitWidth = sprite.width; this.explicitHeight = sprite.height; this.x = sprite.x; this.y = sprite.y; addChild(sprite); } } } </code></pre> <p>which is used in the following way: </p> <pre><code>private var circCentre:Sprite = new Sprite(); circCentre.x = mainContainer.width / 2; circCentre.y = mainContainer.height / 2; circCentre.graphics.lineStyle(3, 0xD0B917); circCentre.graphics.beginFill(0xF2DF56, 0.2); circCentre.graphics.drawCircle(20, 20, 50); circCentre.graphics.endFill(); mainContainer.addChildAt(new SpriteUIContainer(circCentre), 1); </code></pre> <p>The circCentre Sprite never appears on screen and I don't understand how I can get it to appear.</p> <p>Any help much appreciated!</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.
    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