Hello,
I have 2 classes the first of which is my document class that creates a stage sprite that I add an instance of my second class to. My second class is a sprite that contains a shape and a textfield. I am trying to add the textfield as a child of the shape and I can get it to display, but its position is set relative to my stage sprite, which it is a grandchild of, not my menuPanel instance, which it is the child of. According to my searching and the tutorial I am working off of, positioning of addChild is supposed to be relative to the parent. Is this not correct?Code below:
package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.display.Sprite;
public class Game extends MovieClip {
private var iPanel:ExpositionPanel = new ExpositionPanel();
private var iStage:Sprite = new Sprite();
public function Game(){
trace("Program started");
initialize();
}
public function initialize():void{
trace("Program initializing...");
trace("Creating iStage Sprite...");
iStage.graphics.beginFill(0xFFCC00);
iStage.graphics.drawRect(0, 0, 700,700);
iStage.buttonMode = true;
trace("Adding Stage sprite...");
addChild(iStage);
iStage.addEventListener(MouseEvent.CLICK,clicked);
trace("adding Exposition Panel...");
addChild(iPanel);
trace("Adding mouse event listener...");
}
private function clicked(evt:Event):void{
trace("Click registered");
}
}
}
package {
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.TextFieldAutoSize;
import flash.text.AntiAliasType;
public class ExpositionPanel extends Sprite {
private var panelText:TextField = new TextField();
private var menuPanel:Sprite = new Sprite();
public function ExpositionPanel() {
menuPanel.graphics.beginFill(0xFF00FF);
menuPanel.graphics.drawRect(0,200,550,300);
menuPanel.graphics.endFill();
addChild(menuPanel);
panelText.text = "Initialized";
menuPanel.addChild(panelText);
panelText.x = 20;
panelText.y = 20;
}
}
}