A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 29

Thread: Playing a movie clip in reverse

  1. #1
    Hello, I was wondering is someone could point me to a tutorial for playing a movie clip in reverse when triggered by a button.

    I did find one tut on this subject on the site but it uses the Tell Target and I was wondering what the new method would be for doing so.

    I have two buttons, when you roll over one it plays the movie.

    When you roll over two I want it to play in reverse

    Also, if I have a sound loop in the movie clip that is set to stream, will it also play in reverse??

    Can you help?

    Thanks Much!
    Rick

  2. #2
    Senior Member
    Join Date
    Apr 2001
    Location
    UK
    Posts
    493
    in frame one of the root place:

    //place any target MC in place of _root if desired
    _root.onEnterFrame=function(){
    if(forward==1){
    nextFrame();
    }else{
    prevFrame();
    }
    }
    forward=1

    in your buttons place:

    on(rollOver){
    //plays backward
    _root.Forward = 2;
    }

    and:
    on(rollOver){
    //plays forward
    _root.Forward = 1;

    }


    hope this helps





  3. #3
    HELP>>>ACTIONSCRIPT DICTIONARY
    Join Date
    Feb 2000
    Location
    In the Present Moment
    Posts
    1,041
    http://board.flashkit.com/board/show...hreadid=277100

    another solution.. also typing "reverse" into the search engine would have provided many posts on this subject

  4. #4

    dumbfounded

    First I would like to say thanks for the posts.

    Second, I just don't seem to be getting it, so I am going to give a bit more details about my movie and hopefully you can help me understand what is happening.


    Ok, on my main timeline I have a movieclip with instance name "scroller"

    Also on the main timeline I have two buttons one to go forward and one to go back.

    Now, when I rollOver the forward button I want the instance of "scroller" to play and when I rollOut I want it to stop at the current frame.

    when I rollOver the reverse button I want the instance of "scroller" to play in reverse from its current frame and when I rollOut I want it to stop at the current frame.

    I tried a few combinations of things already posted with no luck thus far.

    I am sure it is something simple I have overlooked but I thought If I gave my instance names you might show me an example using my targets.

    Thanks so much for all you help.
    Rick

  5. #5
    HELP>>>ACTIONSCRIPT DICTIONARY
    Join Date
    Feb 2000
    Location
    In the Present Moment
    Posts
    1,041
    so I am going to give a bit more details about my movie
    If you don't give the details in the first place, how are we supposed to figure out what you really want? It is always nice when the people who want/need help are as clear and concise as to what the problems are that they are having and what the desired result is.

    This is what I did, you can follow along I think:

    To prepare I made a "scroller" movie clip, a simple tween of a box that travels from one side of the screen to the other in roughly 40 frames.

    The next thing I did was to create 2 buttons, one for forward and one for reverse.

    Finally I created an empty movieclip, (ctrl+f8, name it 'mt', hit enter and BAM 'mt' movieclip)

    I placed an instance of the mt movieclip on its own layer (for ease of finding it) inside of the 'scroller' movieclip. The 'mt' movieclip spans the same number of frames as the animation.

    I placed this enterFrame code on the 'mt' movieclip:

    Code:
    onClipEvent (enterFrame) {
    	if (_parent.rewind == true) {
    		_parent.prevFrame();
    		if (_parent._currentFrame == 1) {
    			_parent.rewind = null ;
    		}
    	} else if (_parent.rewind == false) {
    		_parent.nextFrame();
    	}
    }
    Basically this is just checking the rewind variable of 'scroller', that is what _parent refers to, "check the variable rewind in the movie clip that this one is sitting in. Because movieclip mt is sitting inside of 'scroller', 'scroller' is referred to as _parent.

    I then get back to my stage. I select the 'scroller' clip and place this code on it. (This is because I don't have any stop frames inside the 'scroller' animation itself):

    Code:
    onClipEvent (load) {
    	stop();
    }
    I then dragged my 2 buttons on the stage. I gave them instance names, 'forward' and 'reverse', and then put this code on frame 1 of my movie:

    Code:
    forward.onRollOver = function() {
    	scroller.rewind = false;
    };
    reverse.onRollOver = function() {
    	scroller.rewind = true;
    };
    forward.onRollOut = reverse.onRollOut = function() {
    	scroller.rewind = null;
    };
    I then tested my movie. Viola!! (sic)

    Alternate buttons.. I could have made buttons the normal way and used:

    Code:
    forward button:
    on (rollOver) {
    	scroller.rewind=false;
    }
    on(rollOut){
    	scroller.rewind=null;
    }
    
    reverse button:
    on (rollOver) {
    	scroller.rewind=true;
    }
    on(rollOut){
    	scroller.rewind=null;
    }
    ...but I didn't.

    Maybe this will help you out. If you post your email or send me one at kevan@convergence.net, I'll send you the .fla.

    Good Luck!




  6. #6

    Smile Thank You!!!!

    Thanks Antibody!

    That did the trick, amazing what being clear can do LOL

    Thanks Again
    Rick

  7. #7
    Junior Member
    Join Date
    Sep 2002
    Posts
    27

    Great! post Antibody, thanks, alot.

    Just one thing I'd like help with. This part:


    onClipEvent (load) {
    stop();
    }

    ... which is attatched to the scroller.

    Does the fact that scroller mc is on the root timeline mean that the above keeps the scroller mc permanently stationary ...

    ... since we keep entering frame 1 of root, which in turn is loading scroller? Took me ages to come up with that and I don't even know if thats right ...

    Thank-you,

    Mark

  8. #8
    Senior Member
    Join Date
    Jan 2001
    Posts
    472
    Just some extra advice-- the practice of "polling", which is basically what is occurring with an enterFrame running constantly whether a button is rolled over or not, is no longer necessary in MX. Try this variation:

    Code:
    function playClip(clip, direction) {
    	if (direction > 0) {
    		clip.onEnterFrame = function() {
    			var newframe = this.currentframe + 1;
    			if (newframe > this.totalFrames) {
    				this.gotoAndStop(1);
    			} else {
    				this.nextFrame();
    			}
    		}
    	} else {
    		clip.onEnterFrame = function() {
    			var newframe = this.currentframe - 1;
    			if (newframe < 1) {
    				this.gotoAndStop(this.totalFrames);
    			} else {
    				this.prevFrame();
    			}
    		}
    	}
    }
    
    forward.onRollOver = function() { playClip(scroller, 1) };
    reverse.onRollOver = function() { playClip(scroller, -1) };
    
    forward.onRollOut = reverse.onRollOut = function() { delete scroller.onEnterFrame };
    What this basically does is create an enterFrame handler ONLY when a button is rolled over. The enterFrame than continues to run until the button is rolled out. Therefore the handler is only running when you need it, not constantly throughout the movie (which could bog things down if you have a lot of clips polling for information). Just a handy new feature of MX.


  9. #9
    Banned
    Join Date
    Apr 2001
    Location
    Montréal, Québec.
    Posts
    25,397
    A lot of code!
    This was much easier in 5!

    http://odin.prohosting.com/~oldnew/f...ing/forrev.htm

  10. #10
    Senior Member
    Join Date
    Jan 2001
    Posts
    472
    Yes, but then your movie was bogged down with a whole bunch of enterFrames running everywhere and you couldn't have your code centralized. I believe the advantages outweigh the disadvantages, though one of the great things is that if you like the Flash 5 version, you can still choose it if you want to. I just wanted to offer alternatives.

  11. #11
    Banned
    Join Date
    Apr 2001
    Location
    Montréal, Québec.
    Posts
    25,397
    You're right! But in this case even if I'm using a control mc, I don't have any "enterframe" events, except when the clip is actually in reverse play. And even then it's only a loop, not really an onClipEvent.
    Just wanted to offer my alternative!

  12. #12
    Junior Member
    Join Date
    Sep 2002
    Posts
    27

    Tyard et al.,

    Thanks for the post - but now I can't get it to work.

    I pasted all your code above in frame 1 of root.

    I have scroller mc with its tween animation.

    I got rid of the mt clip.

    When I test, the animation begins (but it shouldnt) and the buttons just stop the animation !!

    Did I miss a step?

    Thanks,

    Mark






  13. #13
    Senior Member
    Join Date
    Jan 2001
    Posts
    472
    What do you mean you have no enterFrame handlers? Isn't this:

    Code:
    onClipEvent (enterFrame) {
    	if (_parent.rewind == true) {
    		_parent.prevFrame();
    		if (_parent._currentFrame == 1) {
    			_parent.rewind = null ;
    		}
    	} else if (_parent.rewind == false) {
    		_parent.nextFrame();
    	}
    }
    CONSTANTLY running each frame, whether a button is rolled over or not?

    testedge-- I'll copy and paste and get back to you in a moment.

  14. #14
    Senior Member
    Join Date
    Jan 2001
    Posts
    472
    Sorry, typo on my part.

    Code:
    function playClip(clip, direction) {
    	if (direction > 0) {
    		clip.onEnterFrame = function() {
    			var newframe = this._currentframe + 1;
    			if (newframe > this._totalframes) {
    				this.gotoAndStop(1);
    			} else {
    				this.nextFrame();
    			}
    		}
    	} else {
    		clip.onEnterFrame = function() {
    			var newframe = this._currentframe - 1;
    			if (newframe < 1) {
    				this.gotoAndStop(this._totalframes);
    			} else {
    				this.prevFrame();
    			}
    		}
    	}
    }
    
    forward.onRollOver = function() { playClip(scroller, 1) };
    reverse.onRollOver = function() { playClip(scroller, -1) };
    
    forward.onRollOut = reverse.onRollOut = function() { delete scroller.onEnterFrame };
    And if your clip is playing by default, then you need to stop it:

    scroller.stop();

  15. #15
    Banned
    Join Date
    Apr 2001
    Location
    Montréal, Québec.
    Posts
    25,397
    That's Antibody's script! Not mine!

    For your sake and Testedge's, here's that .fla, if you care to have a look!

    http://odin.prohosting.com/~oldnew/f...ing/forrev.fla

  16. #16
    Junior Member
    Join Date
    Sep 2002
    Posts
    27
    Works like a charm.

    I like this way better since the actions are all in one place. And, you don't need no superfluous mt clip.

    Thanks a mill, Tyard.

    Mark

  17. #17
    Junior Member
    Join Date
    Sep 2002
    Posts
    27

    Took me till now to spot the difference.

    Clue - it's just one "_" for all the others with bandy eyes like me,

    Mark

  18. #18
    Banned
    Join Date
    Apr 2001
    Location
    Montréal, Québec.
    Posts
    25,397
    Actually a few "_" were missing!

  19. #19
    Senior Member
    Join Date
    Jan 2001
    Posts
    472
    oldnewbie-- my apologies, I thought you hade posted the previous solution. Did you not provide the code for yours, or did I miss it? I was responding to the code that was offered, not the code that was alluded to-- I have no idea what your solution was, but I stand by my MX improvements.

    And yes, totalFrames should be _totalframes and currentframe should be _currentframe. I wasn't in Flash at the time and was just typing from memory.

  20. #20
    Banned
    Join Date
    Apr 2001
    Location
    Montréal, Québec.
    Posts
    25,397
    I did provide the .fla... But just took it down! It didn't interest Testedge either!

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