Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache flex Flex:为什么线条被画布';背景_Apache Flex_Actionscript 3_Graphics_Canvas - Fatal编程技术网

Apache flex Flex:为什么线条被画布';背景

Apache flex Flex:为什么线条被画布';背景,apache-flex,actionscript-3,graphics,canvas,Apache Flex,Actionscript 3,Graphics,Canvas,我想让我的画布在自己身上画线,但它们似乎是在背景后面画的。发生了什么事,我该怎么做 Main.mxml <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:my="*"> <my:MyCanvas width="300" height="300" id="myCanvas"></my:MyCan

我想让我的画布在自己身上画线,但它们似乎是在背景后面画的。发生了什么事,我该怎么做

Main.mxml

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:my="*">
    <my:MyCanvas width="300" height="300" id="myCanvas"></my:MyCanvas>
    <mx:Button label="Draw" click="myCanvas.Draw();"></mx:Button>
</mx:Application>

谢谢。

显示对象本身的
图形
对象始终位于显示列表的底部。在这种情况下,超类可能会添加一个重叠的子类,可能是在应用白色背景时(不确定我不是Flex专家)

然而,尝试添加一个专门的孩子来吸引他们可能更安全。 这样,您可以更好地控制其可见性:

package  
{
    import mx.containers.Canvas;
    public class MyCanvas extends Canvas
    {

        private var shape:Shape;

        public function MyCanvas() 
        {
            this.setStyle("backgroundColor", "white");

            addChild(shape = new Shape());
        }
        public function Draw():void
        {

            shape.graphics.lineStyle(1);
            shape.graphics.moveTo( -10, -10);
            shape.graphics.lineTo(width + 10, height + 10);
        }
    }
}

谢谢行“addChild(shape=new shape());”需要更改为“rawChildren.addChild(shape=new shape());”应该注意,flex3 sdk==在createChildren()方法中添加子对象的最佳实践。重写受保护的函数createChildren(),让继承的类先“叠加”(99%的时间),然后再添加Child来完成它们的工作。
package  
{
    import mx.containers.Canvas;
    public class MyCanvas extends Canvas
    {

        private var shape:Shape;

        public function MyCanvas() 
        {
            this.setStyle("backgroundColor", "white");

            addChild(shape = new Shape());
        }
        public function Draw():void
        {

            shape.graphics.lineStyle(1);
            shape.graphics.moveTo( -10, -10);
            shape.graphics.lineTo(width + 10, height + 10);
        }
    }
}