• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

Community Beginner ,
Jun 22, 2023 Jun 22, 2023

Copy link to clipboard

Copied

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

Views

121

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 22, 2023 Jun 22, 2023

Copy link to clipboard

Copied

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);

}

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 22, 2023 Jun 22, 2023

Copy link to clipboard

Copied

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.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 23, 2023 Jun 23, 2023

Copy link to clipboard

Copied

LATEST

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);
}
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines