Skip to main content
Participating Frequently
July 26, 2023
Question

Need Assistance with JavaScript and Adobe Animate (CreateJS) Integration Issue

  • July 26, 2023
  • 2 replies
  • 1218 views

I am facing difficulties with running ActionScript animations in the HTML5 canvas using Adobe Animate (CreateJS) integration. Specifically, the printInstanceNames() function, designed to log instance names of movie clips on the stage, is not working as expected. When testing the animation in a browser, the function doesn't log any output to the console, and I'm unable to identify the root cause of the issue.

I have verified that the stage variable is correctly referencing the createjs Stage object and that the init() function, responsible for initializing the stage and calling printInstanceNames(), is being executed after the instances are present on the stage. However, despite these efforts, the function still doesn't work as intended.

Additionally, I noticed a warning message in the console regarding the performance of a setTimeout handler, but it doesn't seem directly related to the problem with printInstanceNames().

I am seeking assistance to understand why the printInstanceNames() function is not logging instance names to the console and to identify any potential issues in the integration of ActionScript with the HTML5 canvas environment.

Any insights, suggestions, or debugging tips would be greatly appreciated. Thank you.

    This topic has been closed for replies.

    2 replies

    JoãoCésar17023019
    Community Expert
    Community Expert
    July 26, 2023

    Hi.

     

    Animate already creates a canvas and a stage global variables in the publishing process. And your stage variable - besides of the conflict - is storing a reference to a newly created stage that has no children. You are not creating a reference to the current stage.

     

    And you can just place your function definitions and calls in the first frame of the main timeline and they should work.

     

    Also, if you want to get the children of any container you just need to access the children property.

     

    Please let us know if you have any further questions.

     

    Regards,

    JC

    Participating Frequently
    July 29, 2023

    Thank you for all your responses. Regardless of my code, I have tested many different simple tests for html5 canvas publishing and I can't get any function to work and it doesn't read my instance names, no matter what. A simple line of console.log(myMovieClip); returns Uncaught ReferenceError: myMovieClip is not defined, and I made sure the mc is on stage and has that instance name which I copied and pasted into the code. 

    Could anything be wrong with my Adobe Animate installation? 

    Thank you!

    JoãoCésar17023019
    Community Expert
    Community Expert
    July 29, 2023

    In the HTML5 Canvas document, any instance created in design time belongs to the current Movie Clip (timeline). So if you have a MC instance called myMovieClip, you need to use the this keyword to access it. Eg.:

    console.log(this.myMovieClip);
    kglad
    Community Expert
    Community Expert
    July 26, 2023

    where's printInstanceNames defined?

    Participating Frequently
    July 26, 2023

    This is my code in the first frame of the movie.

    This is a simple test because I can't get any code to run at all. So I tried this function to see if it would at least return the instances on stage.

    I've checked the javascript file and the HTML. The createjs is there and also the init()

     

    Thank you!

    // Function to initialize the animation
    function init() {
        // Get canvas and stage references
        var canvas = document.getElementById("canvas");
        var stage = new createjs.Stage(canvas);
    
        // Call the function to print instance names of movie clips on the stage
        printInstanceNames();
    }
    
    
    function printInstanceNames() {
        var numChildren = stage.getNumChildren();
        for (var i = 0; i < numChildren; i++) {
            var child = stage.getChildAt(i);
            if (child.name) {
                console.log("Instance name: " + child.name);
            }
        }
    }

     

    kglad
    Community Expert
    Community Expert
    July 26, 2023

    does something call init()?