Skip to main content
Participating Frequently
April 10, 2018
Answered

How do I properly add a movie clip from library to frame with JS?

  • April 10, 2018
  • 1 reply
  • 765 views

I'm using HTML5 Canvas to build a menu.

I have 2 layers: a Javascript layer and a layer for my menu:

I have some movie clips in my library.

When a particular frame loads, I want it to show some movie clip on the stage. When a different frame loads, I want that movie clip to disappear.

Right now, the javascript for the frame with the movie clip looks like this:

if (exportRoot.ControllerStatus == "working")

{

     ControllerWorkingClip = new lib.ControllerWorkingClip();

     this.addChild(ControllerWorkingClip);

     ControllerWorkingClip.setTransform(274.9,380.7,4.452,4.45,0,0,0,39,44.5);

} else

{

     ControllerBrokenClip = new lib.ControllerBrokenClip();

     this.addChild(ControllerBrokenClip);

     ControllerBrokenClip.setTransform(274.9,380.7,4.452,4.45,0,0,0,39,44.5);

}

This adds the proper movie clip to the stage in the right position, but when my frame changes to a different menu, the movie clip is still visible.

As far as I can tell here, "this" is exportRoot.

Is there a way to add the movie clip to the current frame so that the movie clip disappears when the frame changes?

    This topic has been closed for replies.
    Correct answer ClayUUID

    Frames do not "load", therefore neither do they unload. So anything you add with code, you're responsible for removing with code.

    That being said, if you want a particular movie clip to appear on a particular frame, and not appear on other frames, why don't you just put that movieclip on that frame? That's literally what the timeline is designed for.

    1 reply

    ClayUUIDCorrect answer
    Legend
    April 10, 2018

    Frames do not "load", therefore neither do they unload. So anything you add with code, you're responsible for removing with code.

    That being said, if you want a particular movie clip to appear on a particular frame, and not appear on other frames, why don't you just put that movieclip on that frame? That's literally what the timeline is designed for.

    Participating Frequently
    April 10, 2018

    The if statement chooses which movie clip to put on the frame.

    If I have a dozen different movie clips that the if statement can choose from, I don't want them all sitting on the frame in the editor, but hidden, or anything messy like that.

    Legend
    April 10, 2018

    You have two options then...

    1. When navigating away from the frame, use code to remove any clips you've added.

    2. Put all possible clips in a single container clip, one per frame. Put the container clip in the appropriate root timeline frame. Use code to display the clip you want by telling the container clip to go to that frame.