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

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

Explorer ,
Apr 10, 2018 Apr 10, 2018

I'm using HTML5 Canvas to build a menu.

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

Screen Shot 2018-04-09 at 11.00.26 AM.png

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?

697
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

LEGEND , Apr 10, 2018 Apr 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.

Translate
LEGEND ,
Apr 10, 2018 Apr 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.

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 ,
Apr 10, 2018 Apr 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.

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
LEGEND ,
Apr 10, 2018 Apr 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.

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 ,
Apr 10, 2018 Apr 10, 2018
LATEST

#2 is an interesting idea. I'll give that a try.

Thanks

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