在Flex中查找组件的父级

时间:2011-08-03 11:49:21

标签: flex actionscript-3 graphics

在我的应用程序中,我采用了一个面板,并通过给出一些图像路径添加了一个图像。对于该图像,我添加了DrawingArea(自定义)对象并开始绘图。自由手绘后,我将其添加到其父级(通过提供this.addChild(graph);)。这说明什么?我可以给出什么而不是this(特别是在移除特定孩子的情况下)?请原谅我,如果不清楚的话。

    private function StartMarking(eve:MouseEvent):void
    {
        if (!eve.buttonDown)
        {
            isDrawing = false;
        }

        x2 = mouseX;
        y2 = mouseY;
        if (isDrawing)
        {
            drawColor = 0x000000;
            markUp.graphics.lineStyle(2, drawColor);
            markUp.graphics.moveTo(x1, y1);
            markUp.graphics.lineTo(x2, y2);

            drawingStr += x1 + "_"+ y1 +"_";
            x1 = x2;
            y1 = y2;

            this.addChild(markUp);
        }

    }

1 个答案:

答案 0 :(得分:2)

从其父级中删除组件:

if (parent) parent.removeChild(this);

将直接子(“child”)添加到父级:

if (parent) parent.addChild(child);

后者将从当前组件中删除子项,并将其添加到当前组件的父项,以便(current和child)现在都是当前组件父项的子项。好吗?