2

so I have a class:

package
{
    public final class Main extends Sprite
    {
        private var TextHolder:Sprite = new Sprite();

        public function Main():void
        {
            spawnHolder();
        }
        private function spawnHolder():void
        {
            TextHolder.graphics.beginFill(0xFFFFFF);
            TextHolder.graphics.drawRect(0, 0, 100, 80);
            TextHolder.graphics.endFill();
            stage.addChild(TextHolder);
        }
    }
}

but the problem is.. I do not see anything on the stage.. This Main Class is the document class btw.

I'd appreciate it very much if anyone could help me out! Thanks in advance.

~Gg

4

2 回答 2

1

在将显示对象添加到舞台之前,舞台不可用。在这种情况发生之前它将为空。

package
{
    public final class Main extends Sprite
    {
        private var TextHolder:Sprite = new Sprite();

        public function Main():void
        {
            this.addEventListener(Event.ADDED_TO_STAGE,spawnHolder);
        }
        private function spawnHolder():void
        {
            TextHolder.graphics.beginFill(0xFFFFFF);
            TextHolder.graphics.drawRect(0, 0, 100, 80);
            TextHolder.graphics.endFill();
            stage.addChild(TextHolder);
        }
    }
}
于 2012-11-07T14:02:29.627 回答
0

尝试更改颜色,可能您的文档背景也是白色的。不要用大写的命名变量 like TextHoldertextHolder而是使用。尝试在阶段初始化后完成所有工作。

于 2012-11-07T02:43:05.437 回答