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

On exit frame

Community Beginner ,
May 27, 2006 May 27, 2006
Like a couple of earlier posters, I'm surprised that I can't simply detect exiting a frame as a specific event so that I can do something before hitting the next frame.

The example is loading external swfs on frames of a container swf. Each frame represents a site state, and needs to display various things, including an external movie, (different for each frame), using loadMovieNum(). As I leave each container frame, I'd like to explicitly unload the movie used by that frame, as the user can navigate to any frame they want I don't want to have to use unloadMovieNum() everywhere for every movie that may be loaded when user hits a new frame.

I'm considering other strategies, but the neatest would be being able to detect and act on a specific exit frame.

Any suggestions on how to approach this?

Many thanks
TOPICS
ActionScript
1.2K
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 Beginner ,
May 27, 2006 May 27, 2006
By the way, I had been going to load these external movies to different levels. If I am prepared to load all external swfs to the same level, then I don't even have to unload, as the new swf will replace the existing one at that level, right? Even so, surely there would be cases when it would be very handy to be able to execute something on exiting a frame? Any thoughts would be appreciated.
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 ,
May 28, 2006 May 28, 2006
I've never needed such a thing and I suspect the desire for such a thing is due to an mis-understanding of how Flash works.

First of all, there is nothing that does with Flash enters a frame so why aren't you asking for that too? I know there is an onEnterFrame function, but it is poorly named. It doesn't MEAN what it is called. It means to repeat something at the frame rate of the swf. So even a swf with one frame or a stopped clip will execute over and over.

How Flash works is that all the code on a given frame is executed and then the screen is redrawn. In effect, that is "as the player exits the frame." So there is your "event" right there!

There are no times between frames.

So a very simple way to do what you are talking about is to have code like the following on each of your frames. I'm pretending that your external assets are called something like Page2.swf, Page3.swf, etc., that you are loading them into _level5, and that you have already set up a MovieClipLoader to handle the loading.

stop();
if(_level5){
myLoader.unloadClip(5);
}
myLoader.loadClip("Page"+this._currentFrame+".swf",5);

That is it.

PS: Of course I wouldn't do it this way at all. But given what you seem to want there you go.
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 Beginner ,
May 28, 2006 May 28, 2006
Hi Rothrock, thank you for your reply. Yes, I'm aware that onEnterFrame() is actually a loop that spins at the frame rate, and that putting code on a frame ensures that it is executed when the timeline hits that frame. That bit is good, because it is essentially the on enter frame event. I had considered something like you've suggested, and that could be done reasonably neatly in an include. In that case, I'd set up a switch to test for all levels within the range expected and handle them accordingly. As I said, in this case, I've opted for using the same level for all loads, which makes the issue go away.

Even so, it seems to me that exiting a frame is a specific event, and an event model would do well to know about it. (even though, as you say, there is no specific time that Flash knows about between frames). There must be cases when some clean-up would be desireable when leaving a given state, prior to creating a new one.

It has got me thinking that frames may not be the best way to manage state changes. I may opt for a single frame container to load different content. This will probably make it easier to trap changes. I can invoke the same function on every change then without much trouble, and use a switch as described above to give me a bit of a state machine.

Thanks again for your thoughts.
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 ,
May 28, 2006 May 28, 2006
Glad that is going to work out for you. And I think you are onto something there with not really using frames is probably a good path to explore a bit.

Also personally I don't think levels are generally a good idea. To my mind they go against the central paradigm of Flash: The MovieClip class. So personally I much prefer to load external content into movie clips. I just feel Flash gives you better control there.

Good luck with your project.
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 Beginner ,
May 28, 2006 May 28, 2006
Rothrock, hi again. OK, so you would use a single frame container movie that loads different MC symbols from within you FLA and have these (probably single-frame) MCs load external content if required? That's probably preferable because I'll cut down on the external swfs I have to keep track of for run-time deployment. I'll do a few more experiments, then settle on a solution.

Thanks again
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
Contributor ,
May 28, 2006 May 28, 2006
You don't need such an event. Even in Director where you have an on exitFrame it is used to create something that loops too. The same as Flash does with onEnterFrame, there is not such software, or at least that I know that do this. To do something when a button is click use button events instead of waiting when a frame has passed. As you said the user needs to click somewhere, well this button is the one that unloads and then loads the next movie you don't even have to have many frames each one loading a different movie.
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 Beginner ,
May 28, 2006 May 28, 2006
LATEST
Hi juankpro

Yes, I agree that a button will need to be clicked to go somewhere, but I got into this question because I'm using a navigation set that is common to all frames in the container movie. A given button will have to find out either what is loaded in a level, or which frame it is leaving, in order to perform the right action, if that action is going to be different on exiting different frames. A true 'on exit' event must be a good idea for many situations, but my approach is to avoid the problem by changing strategy completely. I'm pretty much going off frames as a state management device and realising that I'll have to manage state explicitly, eg, a switch approach for example.

Cheers
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