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

Is there an event for frame change?

Explorer ,
Apr 10, 2018 Apr 10, 2018

I am building a menu using HTML5 canvas.

The menu has tons of submenus, each of which has a bunch of buttons.

Each button gets an event listener added to it when that frame loads.

Every time the user hits a button, the main timeline skips to a different frame (a different submenu).

From what I've read, I need to remove the event listeners for the buttons that are no longer visible when this happens.

That means most of my buttons need to have code that removes all event listeners, and only then changes frames.

This is bad, since I might forget to add this code to one of my buttons at some point, and the next time I come back to that menu, it'll add a second event listener for the button, making the function that handles the button click fire twice.

Is it possible to add an event listener that triggers when the frame changes? If so, I could just clear all event listeners that I setup on any buttons anywhere every time the frame changes, and not have to do it within each button's code.

503
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

Having button event handlers directly twiddle the current timeline frame is a fairly terrible design. It would be far better to have your button handlers instead call a common function, passing the desired frame as data. Then the common function could handle any necessary cleanup of the current menu before gallivanting off to the next one.

Translate
Community Expert ,
Apr 10, 2018 Apr 10, 2018

hi,

why not just place your entire menu in a MovieClip, and have it on top of your entire project? So it will always be the same menu.... and it will just navigate or load other MovieClips. Then instead of your submenus skipping to a different frame on main timeline, its just moving to a different frame (or I would use Labels) within the main timeline of the MC?

So you could just use a MovieClip for each of your "pages". So think of a MovieClip as a new scene, or even like a new file.... then your entire project can be ONE frame... with a Menu in one MC... and then one Main MC on the main timeline that swaps out the various MC's depending on which menu item is clicked... or the menu can be the same, and load a new URL that has your other sections.

You can swap MCs from the library

hope that helps.

cheers,

mark

headTrix, Inc. | Adobe Certified Training & Consulting
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

That sounds similar to how I do things now, except everything is not contained within a single movie clip.

I have a main timeline, and frame labels for all my frames:

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

Each frame is a different submenu. When a button is hit on any of these frames, it uses gotoAndStop(LABEL) to move the main timeline to a specific submenu.

It sounds like you are proposing I would do exactly that, but inside of a single movie clip.

Then all my submenus are their own movie clips, on their own frames, and I skip between frames like I do now.

Is there some advantage to doing that? Does that help with event listeners somehow?

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

Having button event handlers directly twiddle the current timeline frame is a fairly terrible design. It would be far better to have your button handlers instead call a common function, passing the desired frame as data. Then the common function could handle any necessary cleanup of the current menu before gallivanting off to the next one.

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

Its very different and a better way to work.... for SOOOOO Many reasons. A movie clip can be scaled , duplicated, moved as a group,  all via script or by transforming, and it doesn't matter what is happening on the main timeline. The movieClip is independent and can still do its own thing, even if the Main Timeline is stopped. (If you had to add an animation would you just keep adding frames to the main timeline?? Much easier to place that animation inside a MC, and then just place it on the frame where it should get played, no need to move everything down the timeline)

If your client wants to change all the fonts in your menu, you would have ONE place to go to change the font..... if you had to add more menu items, again its all in the same movieClip, nice and organized, easy to navigate, easier to update, easier to move, you name it.

All your screens can also be ALL together in ONE movieClip... so your menu just navigates to various frames or tables within that MC's timeline. Or they can be separate MC's that get loaded over each other directly from the Library.

Almost everything can be a movie clip.... I used it for animations, or to organize objects, use it for rollover buttons, as a new scene, as a compartment to organize things. Movie Clip is KING!

Just my two cents.

hope this helps.

mark

headTrix, Inc. | Adobe Certified Training & Consulting
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

Movie clips are great, and I do use them.

Having my entire menu inside of a master movie clip doesn't fix my problem with unsetting event listeners (I just tried), and since the menu is the entire project, I have no need to move the menu as a whole, or duplicate it, or anything like that.

Using movie clips creates additional namespaces, and organizes things better (buttons are no longer children of exportRoot - they are children of the movie clip), which is usually a good thing. In my case, this breaks some code I have written earlier that I would rather not rewrite.

ClayUUID's idea of having all buttons call a common function that handles removing event listeners seems to be working. Thanks Clay.

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