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

Create Movie Clip objects dynamically and add them to the Stage with javascript in HTML5 in Animate

New Here ,
Jun 16, 2020 Jun 16, 2020

Copy link to clipboard

Copied

Basically I want to instantiate MovieClip objects and add them to the Stage using Javascript(createjs) from the Actions panel in an HTML5 Adobe Animate project. I think previously this could be accomplished by giving a linkage identifier to the MovieClip in the library and instantiating the MovieClip using that but I don't see that option now. What is the best way to do this in an HTML5 project? 

TOPICS
Code , How to , Other

Views

1.9K

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 16, 2020 Jun 16, 2020

Copy link to clipboard

Copied

Hi.

 

In HTML5 Canvas documents, you must assign a linkage name in the Linkage column in the Library.

JoãoCésar_0-1592333573826.png

 

Any symbol in the Library is a property from the global lib object that is automatically created by Animate when the content is published. To instantiate a symbol at runtime, you must use the linkage name as the constructor method name. Like this:

var platform = new lib.Platform();
platform.x = canvas.width * 0.5;
platform.y = canvas.height * 0.5;
this.addChild(platform);

 

I hope this helps.

 

Regards,

JC

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
New Here ,
Nov 27, 2021 Nov 27, 2021

Copy link to clipboard

Copied

Thanks for that!

Any idea how to set an instance name when we add the new MC?

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 ,
Nov 28, 2021 Nov 28, 2021

Copy link to clipboard

Copied

You're welcome!

 

In the example above, you could write

platform.name = "desiredName";

 

But if you're adding instances at runtime, you can just reference the variable directly (in this case, just platform).

 

Or please provide more details if this is not the answer you're looking for.

 

Regards,

JC

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
New Here ,
Jun 23, 2022 Jun 23, 2022

Copy link to clipboard

Copied

How could I add code from an external class to platform?  If platform is going to be on the screen many times... I have a bunch of functions that I would like to assign to platform as it gets added to the stage.  platform.class = externalClassName;  I am doing what the previous person said. I have movieclips in Flash that previously had a lot of code attached to them. Now in Animate 22, I have the movieclip in the library. I'm adding them to the stage. Now I'd like to just assign them a class somehow. 

 

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 24, 2022 Jun 24, 2022

Copy link to clipboard

Copied

LATEST

EaselJS Tutorial: Inheritance (createjs.com)

 

how to extend class from animate? · Issue #838 · CreateJS/EaselJS · GitHub

 

and from a previous post of mine, Solved: how to extend class from animate (canvas) - Adobe Support Community - 8830551

 

function OpenScreen() {

    var mc =  new lib.OpenScreen_mc();

    mc.newProperty = whatever;

    mc.newMethod = function(){

        do whatever

    }

    return mc;

}

var os = new OpenScreen();

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