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

AddChild Using HTML5 Canvas In Animate 2020

Explorer ,
Nov 12, 2020 Nov 12, 2020

I'm trying to add a movie clip from the library when I click a button on the stage. When I test the movie, I get no reponse when I click the button. Here's the code I'm using. The movie clip I'm trying to add is called "bluBox".

 

var fl_MyInstance = new lib.bluBox();

this.addButton.addEventListener("click", fl_MouseClickHandler.bind(this));

function fl_MouseClickHandler()
{

this.addChild(fl_MyInstance);
}

 

Thanks

1.2K
Translate
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

correct answers 1 Correct answer

Community Expert , Nov 12, 2020 Nov 12, 2020

Hi.

 

Is the linkage name of your symbol set to bluBlox in the Library?

image.pngexpand image

 

Please let us know.

 

Regards,

JC

Translate
Community Expert ,
Nov 12, 2020 Nov 12, 2020

Hi.

 

Is the linkage name of your symbol set to bluBlox in the Library?

image.pngexpand image

 

Please let us know.

 

Regards,

JC

Translate
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
Explorer ,
Nov 12, 2020 Nov 12, 2020

Linkage.pngexpand image

 

Here's what I see in the library

Translate
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 ,
Nov 12, 2020 Nov 12, 2020

your code is failing because you have no linkage id assigned.  the symbol name isn't relevant when using the "new" constructor.

 

do what @JoãoCésar suggested by double clicking in the linkage field of your bluBox library symbol and typing "bluBox" (without quotes).

Translate
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
Explorer ,
Nov 12, 2020 Nov 12, 2020

Linkage_2.pngexpand image

 

Okay, I changed the linkage but it still doesn't add bluBox to the stage when I click the button.

 

Here's the code:

var fl_MyInstance = new lib.bluBox();

this.addButton.addEventListener("click", fl_MouseClickHandler.bind(this));

function fl_MouseClickHandler()
{
alert("Mouse clicked");

this.addChild(bluBox);

}

Translate
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
Explorer ,
Nov 12, 2020 Nov 12, 2020

Okay, it works now. 

 

I screwed up the addChild line.

 

I had "this.addChild(bluBox);"

 

I changed it to "this.addChild(fl_MyInstance);"

 

Thanks for the help 🙂

Translate
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 ,
Nov 12, 2020 Nov 12, 2020

Hi again. Your addChild statement should be:

this.addChild(fl_MyInstance);

 

Translate
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
Explorer ,
Nov 12, 2020 Nov 12, 2020

Thanks, it works now.

Translate
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 ,
Nov 12, 2020 Nov 12, 2020

the addChild part was correct in your original post. 

Translate
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
Explorer ,
Nov 12, 2020 Nov 12, 2020
LATEST

Yes, I screwed that part up.

Translate
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