Solved

Flash move playing in reverse

Posted on 2009-05-07
5
289 Views
Last Modified: 2012-05-06
I have a basic but ok knowledge of Flash however cant seem to figure out this:

On Click of this myButton pay in reverse.
Can anyone help?
Cheers,
N
0
Comment
Question by:Neil_Bradley
  • 3
  • 2
5 Comments
 
LVL 3

Expert Comment

by:mharfouch
ID: 24333435
Add this to your main timeline;

//will stop 'play', 'gotoAndPlay' and 'rewind', 'gotoAndRewind' functions
MovieClip.prototype.stopAll = function () {
        delete this.onEnterFrame;
        this.stop();
}

//will stop 'rewind', 'gotoAndRewind' functions
MovieClip.prototype.stopRewind = function () {
        delete this.onEnterFrame;
}

//will play the timeline backwards and continal to loop until 'stopAll', 'stopRewind' or 'pause' are called
//note: the 'rewind' function will cancel the 'play' function BUT the 'play' function will not cancel the 'rewind' function
//you must call 'stopAll' or 'stopRewind' before using 'play' when your timeline is playing backwards
MovieClip.prototype.rewind = function () {
        this.stop();
        this.onEnterFrame = function () {
                if (this._currentframe > 0) {
                        this.prevFrame ();
                } else {
                        this.gotoAndStop (this._totalframes);
                }
        }
}

//will goto the specified frame and play the timeline backwards and continal to loop until 'stopAll', 'stopRewind' or 'pause' are called
MovieClip.prototype.gotoAndRewind = function (frame) {
        this.gotoAndStop (frame);
        this.rewind();
}

//will pause the timeline for the specified amount of time. will always play forwards when the pause has finished
MovieClip.prototype.pause = function (time) {
        delete this.onEnterFrame;
        secondsToPause = time;
        pauseInt = setInterval (this, "restart", secondsToPause * 1000);
}

restart = function () {
        clearInterval (pauseInt);
        play();
}




And then put this after your onClick function:
instancename.stopAll();
instancename.rewind();
0
 
LVL 5

Author Comment

by:Neil_Bradley
ID: 24340382
Thanks for your responce. I have put together a basic forward and reverse FLA file with your script running however I cant it working. Can you take a look and see where the issue is? I have uploaded the FLA file here http://www.beaconhilldesign.co.nz/experts_exchange/reverse.zip

N
0
 
LVL 3

Expert Comment

by:mharfouch
ID: 24343541
Can not open the file in CS4?

What did you use to make it?
0
 
LVL 5

Author Comment

by:Neil_Bradley
ID: 24345586
CS3, I will take another look it it today and see if fresh eyes helps. Did you use AS2 or 3 to write your script?
Cheers,
N
0
 
LVL 5

Accepted Solution

by:
Neil_Bradley earned 0 total points
ID: 24382449
I tried a few ways but could not get your solution to work. After a bit of reaserach I found this (see attached).
The script is dropped into the button works a treat.
Cheers,
N

var rewind:Boolean = false; 

btn_back.addEventListener(MouseEvent.CLICK, forward); 

btn_back.addEventListener(MouseEvent.CLICK, backwards); 
 

function forward(event:MouseEvent):void{ 

    rewind = false; 

    addEventListener(Event.ENTER_FRAME, eFrame); 

} 
 

function backwards(event:MouseEvent):void{ 

    rewind = true; 

    addEventListener(Event.ENTER_FRAME, eFrame); 

} 
 

function eFrame(e:Event):void{ 

    if(currentFrame <= 1 || currentFrame >= 60){ 

        //  limit movement between frame 1-60 

        removeEventListener(Event.ENTER_FRAME, eFrame); 

    } else { 

        //  move forward or back depending on rewind 

        (rewind) ? prevFrame() : nextFrame(); 

    } 

} 

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now