Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / Flash / Flash Actionscript / July 2008



Tip: Looking for answers? Try searching our database.

Executing code after a certain frame

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
phonemymum - 18 Jul 2008 18:10 GMT
I am trying to get my MC to move on frame by frame from a particular starting
frame in the movie.  Anything below the stated frame I don't want anything to
happen. I've tried this

if (this._currentframe >= 6 )
{
trace ("more than 6")
var frameGo = function () {nextFrame ();}
var myTimer = setInterval(frameGo , 20000);
}
else if (_currentframe <= 5){
trace ("less than 6")
}

This doesn't work. Using this code without the if/else statement:

var frameGo = function () {nextFrame ();}
var myTimer = setInterval(frameGo , 20000);

Works but accross the whole movie,

How do I get the code to execute after a certain point only?

Help most appreciated!

Chris
BuG300K - 18 Jul 2008 21:36 GMT
I'm not too sure...Why not just put the code on the 6th frame of the movie clip?
MATTANDIE - 18 Jul 2008 21:41 GMT
You pretty much have two options to accomplish what you want. The easiest is to
call the function at frame the frame you want to start at . If that is an
unnacceptable solution you will need 2 intervals not just one. something like
this should work:

// first interval function for all frames before 6
function timerStart(){
   
  if(this._currentframe >= 6){
     
           clearInterval(myTimer2)
           frameGo();
      }   
}

//second function to call what you want.
function frameGo(){
       
           var myTimer:Number =  setInterval(frameGo, 20000)

// your next frame functionality    
   if (_currentframe < _totalframes){
     
            nextFrame();
       }
   
// clears the interval once you get to the last frame
    else if (_currentframe == _totalframes){

            clearInterval(myTimer);
           
       }
};

var myTimer2:Number = setInterval(timerStart, 100);
phonemymum - 19 Jul 2008 08:11 GMT
Hi guys thanks for the responses.

It doesn't matter where I place this code on the timeline it executes across
the whole of the movie:

var frameGo = function () {nextFrame ();}
var myTimer = setInterval(frameGo, 20000);

This is fine for all frames above and including 6 - but if I'm back at the
menu system from frames 1 - 5 (different sequences in the menu) - the code is
STILL executing which I don't want to happen.

Hence why I've been trying to implement and if/else statement.  MATTANDIE I
tried your code and it doesn't appear to solve the problem. It is advancing the
playhead still across these first 5 frames.

What I don't understand which may be part of the reason why this is not
working is I can't trace the if statement - the output is not telling me that
I'm at or above frame 6. The first two lines of code in this case in this
instance are going to execute anyway despite what I declare in the if/else
block. Perhaps I need to write the following so that the setInterval is
incorporated in this block.

var frameGo = function () {nextFrame ();}
var myTimer = setInterval(frameGo, 20000);
 
if (this._currentframe >= 6 )
{
trace ("more than 6")
frameGo ();
}
else if (this._currentframe <= 5){
trace ("less than 6")
clearInterval(this.myTimer);
}

This may be what you were trying to get me to do MATTANDIE but it's not
working for me. In your code example I notice your declaring the function
frameGo () from frame 5 and below - I think I want it to do the opposite.

Any more help appreciated :-)
MATTANDIE - 21 Jul 2008 14:19 GMT
The code i provided works if you put it in the first frame of your movie. the
first interval checks for the _currentframe to be less than 6. if you just want
to start at a later frame, you can just use the second interval or a variation.

I hope this helps.
phonemymum - 21 Jul 2008 15:45 GMT
Thanks for the response!

I played round with the code and no joy. I did as you had said - that first
statement block reads:

if the playhead is at a frame number greater than or including 6 then execute
the function goFrame ();. Accept that it appears that

var myTimer:Number =  setInterval(frameGo, 20000)

Is executing anway in spite of it being part of a function that should only be
called when the playhead reaches frame 6. This is what I kept finding when I
was trying.

In the hope you can cast some more light I'm uploading a down and dirty FLA or
what I'm trying to do. If you wait at the first frame the interval is executing
- similar you can jump to the 6th frame - the interval works, which is great
but if you return to the first frame the interval is still working!

http://www.christopherbarnard.co.uk/frame.rar

Thanks for taking the time.
MATTANDIE - 21 Jul 2008 16:09 GMT
Ok, What i gave you was a pair of generic interval loops designed to play
through a movie and adjust the movie speed once it hits frame 6 then play to
the end at the new speed. With the way you have your file set up, you will have
to make some modifications to get it to work the way you want it to. Start by
adding a trace function to both intervals so you can see when its called. Then
look at adding a clearInterval(frameGo); to either the timerStart function or
your "return to menu" button functionality.

let me know if you still cant get it to work after you have tried these things.
phonemymum - 21 Jul 2008 17:17 GMT
Struggling.

The problem is I can't rely on buton actions at the beginning of the movie to
initiate any functions, because the button actions are coming from XML data
strings - and that gets much too complicated for me at the moment!

It makes no sense to me (and curse my limited knowledege) that you can't use
the if/else function thus:

if (currentframe >= 6 )
{
trace ("more than 6")
frameGo ();
}

The trace above never works which makes me think it is a scope issue? What
amazes me further is that if the frameGo (); function is just that wrapped up
in a function it appears to run anyway?

This is why I'm so confused.

Let me know if you can help me any further....

Chris
MATTANDIE - 21 Jul 2008 19:06 GMT
Ok Chris, I took a closer look at it over lunch, and with what you have set up
putting this code on frame 6 will make it work.  ** please note that once you
go back to the first frame your interval will complete its loop but will not
progress the frame, then it stops.

As to why you cant use just the if/else statement: The if/else statement by
itself wont get called more than once unless it is in either an interval or an
onEnterFrame function.

// this is necessary to reset the timer when you go to this frame.
clearInterval(intervalID);

//main function.
function frameGo(){

// if frames are greater than or = to 6 and less than the total frames
   if (_currentframe < _totalframes && _currentframe >= 6){
              trace("frameGo currentframe = " + _currentframe)
            nextFrame();
       }
   
// clears the interval once you get to the last frame
    if (_currentframe == _totalframes){

            clearInterval(intervalID);
           
       }
//clears the interval if you go back to frames 1-5
//** note: the current loop will keep going until it is completed. then it
will be cleared.
    else if (_currentframe < 6){ clearInterval(intervalID);
            trace("should clear myTimer")
    }
};
intervalID =  setInterval(frameGo, 20000)

stop();
phonemymum - 23 Jul 2008 06:51 GMT
Thanks so much for looking at that. I've been absent so excuse me for not
getting back quicker!

Right that does work exactly how I wanted - thanks so much. And the code is
logical for me to understand.

The only thing is that I notice when you jump to the first frame after 6, the
interval seems random...i,e, it plays for only a few seconds then jumps to the
next frame. When it goes to the next frame it traces currentframe - not when
you first click.

That's really weird isn't it it isn't tracing the frame when it hits the first
frame it is only doing it when it cycles to the next frame in the sequence?

Personally I can't see how that is possible?

You've done so much - so don't worry if that's enough for you...thanks for
your continued help.

Chris
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.