Actionscript 3 在actionscript中输入角度时是否过度绘制圆?

Actionscript 3 在actionscript中输入角度时是否过度绘制圆?,actionscript-3,actionscript,actionscript-2,geometry,Actionscript 3,Actionscript,Actionscript 2,Geometry,这个代码就是问题所在。CircleSlider是一个独立的类。我试过这样做 var circleSlider:CircleSlider=new CircleSlider(120,angle);//draw Circle According to the angle i think here is problem becoz every time clicked it creates new circle and draw over the old circle. 但它通过静态

这个代码就是问题所在。CircleSlider是一个独立的类。我试过这样做

      var circleSlider:CircleSlider=new CircleSlider(120,angle);//draw Circle    According to the angle i think here is problem becoz every time clicked it creates new circle and draw over the old circle.
但它通过静态类型CircleSlider的引用对可能未定义的方法CircleSlider进行错误调用

当我运行程序时,输入值为90。

然后我输入另一个值180,然后它变为


如何克服此错误

每次执行单击处理程序时,您都在创建circle类的新实例并将其添加到阶段,而不删除旧实例。我认为最好的解决方法是将CircleSlider类的构造函数中的逻辑移到一个单独的公共方法中,比如draw,然后在click处理程序中调用它

您的代码如下所示:

      circleSlider.CircleSlider(120,angle);  
// Set up the circle once
var circleSlider = new CircleSlider();
circleSlider.x = stage.stageWidth / 2;
circleSlider.y = stage.stageHeight / 2;
circleSlider.addEventListener(CircleSliderEvent.CHANGE,  circleSliderEventHandler);

// and add it to the stage once
addChild(circleSlider);

function click_handler(event:MouseEvent):void
{
       var txt:String = theTextField.text;
       ang = Number(txt);

       if (ang<0)
       {
          angle =  -  ang;
       }
       else
       {
          angle = 360 - ang;

      }
        // Now simply redraw in the same circle instance
       circleSlider.draw(120,angle); //draw Circle    According to the angle i think here is problem becoz every time clicked it creates new circle and draw over the old circle.
}

它起作用了,谢谢你,不用麻烦了,很高兴它起了作用!
// Set up the circle once
var circleSlider = new CircleSlider();
circleSlider.x = stage.stageWidth / 2;
circleSlider.y = stage.stageHeight / 2;
circleSlider.addEventListener(CircleSliderEvent.CHANGE,  circleSliderEventHandler);

// and add it to the stage once
addChild(circleSlider);

function click_handler(event:MouseEvent):void
{
       var txt:String = theTextField.text;
       ang = Number(txt);

       if (ang<0)
       {
          angle =  -  ang;
       }
       else
       {
          angle = 360 - ang;

      }
        // Now simply redraw in the same circle instance
       circleSlider.draw(120,angle); //draw Circle    According to the angle i think here is problem becoz every time clicked it creates new circle and draw over the old circle.
}
// Assumes you're drawing in the graphics property of the class
this.graphics.clear();