Skip to main content
Participating Frequently
June 23, 2023
Question

Unable to clear the child (an angle) on the canvas before creating the next child (a new angle)

  • June 23, 2023
  • 1 reply
  • 184 views

The aim of this application is to generate angles so that students can state what type (e.g. acute etc)

I can generated an angle, but I can't remove this angle so a new angle can be added. They just build up on top of each other.

I have uploaded the code.

I'm just wondering if anyone can perhaps help with this problem.

I've tried removeChild, and I think I am heading in the right direction, but just don't have it right.

 

Here is how I added the child to the stage.

stage.addChild(shape);

... and here is a link to see what is happening when I create the new question (i.e. press GO again).

 

https://mymathsroom.com/angles/

 

Thanks

    This topic has been closed for replies.

    1 reply

    kglad
    Community Expert
    Community Expert
    June 23, 2023

    if you're not going to assign unique names to each angle, then add them all to the same parent so you can remove them all without needing a name.  eg:

     

    var angleP:MovieClip=new MovieClip();

    stage.addChild(angleP);

     

    call removeAnglesF when desired 

     

    function removeAngelesF():void{
    for(var i:int=angleP.numChildren-1;i>=0;i--){
    angleP.removeChildAt(i);

    }

    }

    rodecssAuthor
    Participating Frequently
    June 23, 2023

    I think I am heading in the right direction with your answer. I havn't got it working yet.

    One thing is that I did not create movieclips, but used this command ....

     

    var shape = new createjs.Shape();

     

    So I am not quite sure how to get the id of the instance on the stage (if it is considered an instance like a movieclip would be).

     

    I'll keep at it though.

     

    Thank you.

     

    kglad
    Community Expert
    Community Expert
    June 23, 2023

    if you have an html5 project, use:

     

    var angleP = new createjs.MovieClip();
    stage.addChild(angleP);
    function removeAnglesF() {
    for (var i = angleP.numChildren - 1; i >= 0; i--) {
    angleP.removeChildAt(i);
    }
    }