Skip to main content
Participating Frequently
May 4, 2022
Question

Adding an object to a specific frame in a dynamically created movie clip

  • May 4, 2022
  • 1 reply
  • 239 views

Hello,

I have created an mc in the library for a specific purpose and I can load it dynamically. Its shape is a square. The square works fine with labels for up, down, over etc.

For a new project I will need to have a shape that needs to be a randomly sized rectangle. How do I build the movie clip, with javascript, so that it has 4 frames and the labels up, over etc, in it?

I believe if I could do this then I could just make it work the same as the square built in the authoring environment.

I have read the createjs movie clip definitions and I can see addchild(shape) but I can't understand how to add shape1 to frame 1, shape2 to frame 2 etc.

Any help would be appreciated.

Ron

    This topic has been closed for replies.

    1 reply

    kglad
    Community Expert
    Community Expert
    May 5, 2022

    even easier, you can use the square you aleady have and resize it (and everything on it's timeline) using js, and/or you can create a new movieclip which has different shapes on the parent movieclip's 4 frames. 

     

    you could even add movieclips instead of shapes to each of those 4 frames and control the sizing of those 4 movieclips independently of the of other 3.

     

    and you can do what you asked, by repeatedly utilizing gotoAndStop and then adding the shape/object your want to the parent movieclip timeline.

    Participating Frequently
    May 5, 2022

    Thank you for responding kglad!

    The reason I want to create the rectangle clip rather than resize the square clip is that the rounded corners also get scaled and, frankly, look odd.

    If I am to understand you correctly, I first create a new clip using: 

    var mc = new createjs.MovieClip(); 
    myParentClip
    .addChild(mc);// Then I use gotoAndStop()
    mc.gotoAndstop(0)
    var shape0 = new createjs.Shape();
    mc.addChild(shape0);
    mc.gotoAndstop(1)
    var shape1 = new createjs.Shape();
    mc.addChild(shape1);//etc
    If my understanding is correct, great!
    How do I add the labels "natural", "highlight", "correct" and "incorrect" to frames 0,1,2,3?
    The reason I have to ask is that I cannot find what 
    labels:{myLabel:20} means in the documentation,
    var mc = new createjs.MovieClip({loop:-1, labels:{myLabel:20}});

    Ron

     

    kglad
    Community Expert
    Community Expert
    May 6, 2022

    i don't think you can use js to add frames to a movieclip. so, in animate create a four frame movieclip with the labels you want.  then proceed with your code.