dcsimg
A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: [RESOLVED] timer and setInterval

  1. #1
    Member
    Join Date
    Apr 2009
    Posts
    51

    resolved [RESOLVED] timer and setInterval

    Hello,

    I'm trying to get a movie clip to automatically load up another external clip, after playing an embedded flv.

    This is what I've tried so far:

    var holdFrame = setInterval( holdFrame, 5000);
    gotoAndPlay(
    _root.mc_holder.loadMovie("swf/library.swf"));
    clearInterval (holdFrame);


    Although it throws no errors, the setInterval is ignored and it just loads direct into the next mc clip.

    Can anyone shed some light as to where I'm going wrong?
    Thanks

  2. #2
    Member
    Join Date
    Apr 2009
    Posts
    51
    I realise now that setInterval may not be the best solution, does anyone know what would be?

  3. #3
    Member
    Join Date
    Apr 2009
    Posts
    51
    It seems that its not possible?

  4. #4
    Senior Member
    Join Date
    Aug 2006
    Posts
    322

    Are You Looking for this?

    PHP Code:
    var intervalId:Number;
    var 
    count:Number 1;
    var 
    maxCount:Number 1;
    var 
    duration:Number 5000;

    function 
    executeCallback():Void {
     
    trace("executeCallback intervalId: " intervalId " count: " count);
     if(
    count >= maxCount) {
     
    clearInterval(intervalId);
     } 
     
    count++;
    }

    intervalId setInterval(this"executeCallback"duration); 
    Note:

    This code is from adobe help under actionscript 2 "ActionScript language elements > Global Functions > setInterval function".


    marlopax
    Last edited by marlopax; 05-25-2010 at 06:09 AM.

  5. #5
    Tim (Super Moderator) Northcode's Avatar
    Join Date
    Dec 2000
    Location
    Whitehorse YT
    Posts
    3,766
    if you only want it to execute once you can use setTimeout instead of setInterval. The syntax is the same but it only calls the callback function once.

    @tabus, your orignal code was just wrong, that's why it didn't work. setInterval returns the id of the timer it creates so that you can kill it later. The first parameter to setInterval has to be a function that you want called when the interval expires.

    Code:
    var id = setInterval(myFunction, 5000);
    function myFunction()
    {
       clearInterval(id);
       gotoAndPlay(_root.mc_holder.loadMovie("swf/library.swf"));
    }
    It looks like you might have been trying to use an anonymous function. If that's what you were trying to do, then this is how you woud do it...

    Code:
    var holdFrame = setInterval( 
    function() 
    {
    gotoAndPlay(
    _root.mc_holder.loadMovie("swf/library.swf"));
    clearInterval (holdFrame);
    } , 5000);
    When your swf2exe tool just HAS to work
    there's only one choice... SWF Studio

  6. #6
    Member
    Join Date
    Apr 2009
    Posts
    51
    Thanks for your help on this.
    I'm working through an old ActionScript 2 book, but I don't think the setInterval is what I need.

    What I need to achieve is to delay a frame, so the flv can play, then time the length (about 2 secs) in AS code so that upon this given time ends, the script then automatically loads the next movie clip in the holder.

    I've tried both your codes and they work for the entire clip but not for the frame, so the animation loads, works fine, gets to the flv and returns back to the start of the animation rather than holding on the frame for the 5 secs to play the flv. So it allocates the code to the whole mc.

    Is there no behaviour function that has a frame delay timer?
    Last edited by tabus; 05-25-2010 at 11:26 AM.

  7. #7
    Tim (Super Moderator) Northcode's Avatar
    Join Date
    Dec 2000
    Location
    Whitehorse YT
    Posts
    3,766
    If you want to stop on a frame, use gotoAndStop() then in the frame you use stop() and you can set up a timer to issue the next gotoAndStop. This has nothing to do with standalone support or projectors though, so I'm moving it to a more appropriate section of the board.
    When your swf2exe tool just HAS to work
    there's only one choice... SWF Studio

  8. #8
    Member
    Join Date
    Apr 2009
    Posts
    51
    Thanks for the tip,
    Sorry about posting on the wrong board, just I'm producing it for a cd-rom, so thought it would be the right place.

    Thanks again

    p.s. what section have you sent the post?

  9. #9
    Tim (Super Moderator) Northcode's Avatar
    Join Date
    Dec 2000
    Location
    Whitehorse YT
    Posts
    3,766
    Flash Newbies there's a permenent redirect from the thread you started in the Standalone & Applications forum.
    When your swf2exe tool just HAS to work
    there's only one choice... SWF Studio

  10. #10
    Member
    Join Date
    Apr 2009
    Posts
    51
    Thanks,
    I got your script worked by the way, so problem solved.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center