Reputation: 4934
As requested, I'm giving a more detailed description of the problem...
First off I have this MXML:
<mx:Panel x="270" y="10" width="690" height="680" id="mainContainerPanel">
<mx:Canvas x="270" y="10" width="670" height="640" id="canvas" initialize="onInit()">
<mx:Script>
protected function onInit():void
{
spiro = new Spirograph(canvas);
}
</mx:Script>
</mx:Canvas>
</mx:Panel>
This passes the tag object to the constructor of my main AS3 class file. This works fine, where in the constructor I have:
function Spirograph(canvas:Canvas):void
{
mainContainer = canvas;
mainContainer.graphics.beginFill(0xFFFFFF);
mainContainer.graphics.drawRect(0, 0, 670, 640);
mainContainer.graphics.endFill();
}
At the moment, I am adding all Sprite objects to the mainContainer by using a wrapper class called SpriteUIContainer:
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);
}
}
}
which is used in the following way:
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);
The circCentre Sprite never appears on screen and I don't understand how I can get it to appear.
Any help much appreciated!
Upvotes: 0
Views: 2293
Reputation: 39408
By 'attached' do you mean you are adding new sprites to the UIComponent using the addChild method?
If so; You'll have to add code to size and position that new 'sprite' relative to the other objects in the container. There is no such code in your example. I recommend implementing this code in updateDisplayList().
More information on updateDisplayList() is in this Flex Component Lifecycle documentation.
If you need more help, you'll have to expand on how your adding new sprites to the UIComponent instance; and perhaps show an example where you add more than one.
Upvotes: 1