A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: playing only specific frames problem

  1. #1
    Member
    Join Date
    Jul 2004
    Posts
    46

    playing only specific frames problem

    I've searched on the forums and have not found a solution so hopefully this isn't too much of a request for help.

    On my main timeline I have a movie clip which within it consists of a 60 frame animation. Now on the main timeline are buttons which when clicked I would like to play that movie clip.

    Now here is my problems or questions. If you press, say button 1 it will play the entire animation. Now if you press button 2 I would like for it to play only the first 30 frames and then stop and stay at frame 30 of the animation. From what I gather I don't think there is a stop command in the mc on frame 30 or the button 1 function would never play all 60 frames. I have the button 1 code to be:
    on (release){
    _mc.gotoAndPlay(1);
    };

    button 2?
    on (release){
    _mc.gotoAndPlay(1);
    if(30){
    stop();
    }
    };

    Please help I am at a loss.

  2. #2
    Member
    Join Date
    Jun 2006
    Location
    Leeds UK
    Posts
    84
    hey

    this might be a very strange way to do it but hey it works so try it!!

    add this action to frame where your button 2 is located:

    // something to track the vaule of this button (pressed or not)
    pressed=false;

    button2.onRelease=function()

    {
    //button2 is pressed now so play mc and change pressed value to true!!
    pressed=true;
    mc.gotoAndPlay(2);

    }

    no go into mc timline and add stop() to the first frame and go to frame 30( where you want the animation stop if button2 is pressed) and make it a key frame and add this code to that frame (keyframe#30):

    if((_currentframe==30)&&(_root.pressed==true))
    {
    stop();
    }

    which simply means if frame number is equal to 30 and button 2 is pressed stop playing!!

    hope this help

  3. #3
    Member
    Join Date
    Jul 2004
    Posts
    46
    Hey FlashSmashed.
    Thanks for the reply. I'll give it a try and post back here if it is successful or if I still have problems EEK!

  4. #4
    Member
    Join Date
    Jul 2004
    Posts
    46
    Ok
    I did as you suggested with the code and nothing happened. I played around a little bit and got most to work but I still have a slight problem.

    I changed the mc.gotoAndPlay on the buttons to just gotoAndPlay.
    Reason - with mc.gotoAndPlay nothing happens, but removing the mc. the animation then plays. The mc on the main timeline is the same length as the frames within the MC so it plays the whole thing. If MC on main timeline only is 1 frame it doesn't play, just skips to next part on main time line.

    Anyway, when I press button 1 the full animation of the mc plays and then moves on to the next part of the main timeline, perfect. When I press button 2, the animation starts and then would appear to stop on frame 30, then jumps to the next frame after the animation on the main timeline. I hope this is clear. I feel it is close and do appreciate your help. Any other suggestions?
    Last edited by FreakyMaranara; 07-12-2006 at 01:42 PM.

  5. #5
    Member
    Join Date
    Jul 2004
    Posts
    46
    Ok I believe I might have solved it.

    I ended up placing a stop on the main timeline at the beginning of the mc. I then moved the buttons from the main timeline that controlled the mc, to within the mc. From there I just edited the code from mc.gotAndPlay to _root.mc.gotoAndPlay, etc. Works like a charm starts and stops where it needs to.
    Is it possible that at the stop on frame 30 if I have some buttons which leads to different pages within the animation, that when pressed plays frames 31 - 60 then goes to the appropriate page? How can I play that then pass the value to go to the appropriate page after the animation.

    Thanks for all your help.
    Last edited by FreakyMaranara; 07-12-2006 at 02:18 PM.

  6. #6
    Flash Filosopher
    Join Date
    Apr 2006
    Location
    Washington
    Posts
    68
    Is it possible that at the stop on frame 30 if I have some buttons which leads to different pages within the animation, that when pressed plays frames 31 - 60
    Yes, just put a this.gotoAndPlay(31) on the release code/function for the button.
    then goes to the appropriate page? How can I play that then pass the value to go to the appropriate page after the animation.
    You could do this a number of ways - one would be to have a variable like

    Code:
    var frameJump:Number = 0;
    and then have code on the button that gets clicked specify the scene or frame you want to go to, such as:

    Code:
    frameJump = 65;
    so then at frame 60, on a keyframe on the timeline put:

    Code:
    gotoAndStop(frameJump);
    which will advance to the specified frame set by whichever button you clicked.
    Last edited by Telmari; 07-12-2006 at 02:33 PM.

  7. #7
    Member
    Join Date
    Jul 2004
    Posts
    46
    Thanks for the reply. Let me explain what I have and see if maybe the code you suggested will still work. Basically I have a room in which when an object is pushed would go through an animation an enter a book. The animation is the one which was discussed in the above posts. and is the mc on the main timeline. After that mc I have the book which has pages in which the user may flip through. When within the book I can use this code to go to a specific page, ex:
    Code:
     on (release) {
       _root.gotoPage(5);
                     }
    Now I'm assuming by your code that when I am at frame 30 and want to play 31-60 then goto page 6 of this book I can place the code:
    Code:
    on (release) {
       this.gotoAndPlay(31) {
            if(_currentframe==60)
                     { 
                           _root.gotoPage(6);
                     }
               }
    }
    Something like this would be similar for all the buttons depending on the corresponding page within the book they need to go to? Can this be done or something similar to the var frameJump but somehow a var gotPage?
    Last edited by FreakyMaranara; 07-12-2006 at 05:13 PM.

  8. #8
    Flash Filosopher
    Join Date
    Apr 2006
    Location
    Washington
    Posts
    68
    Quote Originally Posted by FreakyMaranara
    Thanks for the reply. Let me explain what I have and see if maybe the code you suggested will still work. Basically I have a room in which when an object is pushed would go through an animation an enter a book. The animation is the one which was discussed in the above posts. and is the mc on the main timeline. After that mc I have the book which has pages in which the user may flip through. When within the book I can use this code to go to a specific page, ex:
    Code:
     on (release) {
       _root.gotoPage(5);
                     }
    Something similar, yes.. you'll need something other than gotoPage();, unless that's a function you write. Maybe gotoAndStop/Play (framelabel or number) would suffice, or else write a gotoPage function that interpreted everything.


    Quote Originally Posted by FreakyMaranara
    Now I'm assuming by your code that when I am at frame 30 and want to play 31-60 then goto page 6 of this book I can place the code:
    Code:
    on (release) {
       this.gotoAndPlay(31) {
            if(_currentframe==60)
                     { 
                           _root.gotoPage(6);
                     }
               }
    }
    Something like this would be similar for all the buttons depending on the corresponding page within the book they need to go to? Can this be done or something similar to the var frameJump but somehow a var gotPage?
    Pretty similar. You won't want to use the if(_currentframe == 60) part unless you're testing against something dynamic (here, since the first thing you do is gotoAndPlay(31), you'll never execute the next part, since it's not going to re-check to see what the current frame is every second).

    Best in this case to just put the logic for frame 60 on frame 60 on the timeline, and then send the corresponding variable along with it, like I mentioned above. And yes, you can definitely use any variables you need to help keep track of what frame you need to go to next, etc. Basically, if I understand you, all you need to do is have the mc play 31-60 (no matter what button is pressed) and once at 60, go to a specific frame that varies depending on the button they pressed, in which case setting a temp variable like frameJump or pageNum (assuming Flash knows what a 'page' is and how to navigate there) should work just fine.

  9. #9
    Member
    Join Date
    Jul 2004
    Posts
    46
    Hey Telmari thanks alot. Based on what you had suggested I was able to figure it out. I created a variable at the beginning of the site var pgnum:Number = 0;
    Then once in the office each button was assigned a pgnum = ?; // this whatever the number it needs to go to. ex pgnum = 10:
    then I put the old gotoAnd Play(31);
    All this on the button. At the beginning of the book I put gotoPage(pgnum);
    gotoPage was another declaration made at the beginning which allowed for the page turning and to which page it needs to go to.
    So I would like to thank both you Telmari and FlashSmashed for your suggestions. Flash Kit is a wonderful site and the community of help here is very valuable. The challenges of Actionscript and the assistance of those experienced like the two of you is what makes Flash and Web Page development fun. Thanks to both of you again!

  10. #10
    Flash Filosopher
    Join Date
    Apr 2006
    Location
    Washington
    Posts
    68
    Glad to help! Hehe, now that you know how to do this kind of thing, you get to share it with the next person, and on and on Hopefully eventually we will all know everything :P

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