Play and stop movie clip functions in Flash as

Source: Internet
Author: User
Tags event listener

You can start or stop playing the SWF file by using the play () and the Stop () global function or the equivalent MovieClip method. For example, you can use Stop () to stop playing the SWF file before you continue playing the next scene at the end of a scene. After the SWF file has stopped playing, you must explicitly indicate that you want to start playback again by calling play () or gotoAndPlay ().

You can use Play () and the Stop () function or the MovieClip method to control the main timeline or the timeline of any movie clips or loaded SWF files. The movie clip you want to control must have an instance name and must be displayed on the timeline.

The following on (press) processing function attached to a button starts the playhead movement in the SWF file or movie clip that contains the button object:

The code is as follows Copy Code

Attaching to Button instances
On (Press) {
Play the timeline that contains the button
Play ();
}


This same on () event-handling function code produces different results when it is attached to a movie clip object instead of a button. When attached to a button object, by default, statements generated within the on () handler function apply to the timeline that contains the button. However, when you attach to a movie clip object, the statements generated within the on () processing function apply to the movie clip that has the on () processing function attached.

For example, the following onpress () processing function code stops the timeline of a movie clip that has a processing function attached to it, rather than the timeline that contains the movie clip:

The code is as follows Copy Code

Attach to MYMOVIE_MC movie clip instance
Mymovie_mc.onpress () {
Stop ();
};


The same applies to the onclipevent () processing function attached to the movie clip object. For example, the following code stops the timeline of a movie clip that contains the onclipevent () processing function when the movie clip is first loaded or on the stage.

The code is as follows Copy Code

Onclipevent (load) {
Stop ();
}

It's all about AS2, and if you're AS3, we can

You can call a function to detect the current frame of the movie clip, such as the movie clip name MC1, by listening to the Enter_frame event, and then detect whether the mc1.currentframe value of the moment is the same as the Mc1.currentframe value of the previous time, If the same is paused, if not the same is playing


play movie clips and stop playback
the play () and stop () methods allow for basic control over the movie clips on the timeline. For example, suppose you have a movie clip symbol on the stage that contains an animation of a bicycle across the screen, with its instance name set to bicycle. If you attach the following code to keyframes on the main timeline,

Bicycle.stop (); The bike will not move (it will not play its animation). The movement of bicycles can begin with some other user interaction. For example, if you have a button named Startbutton, the following code on a key frame on the main timeline causes the animation to be played when you click the button:

The code is as follows Copy Code
This function would called when the button is clicked. It causes the
Bicycle animation to play.
function Playanimation (event:mouseevent): void
{
Bicycle.play ();
}
Register the function as a listener with the button.
Startbutton.addeventlistener (Mouseevent.click, playanimation);

Fast forward and back
the play () and stop () methods are not the only way to control playback in a movie clip. You can also use the NextFrame () and Prevframe () methods to manually move the playhead forward or backward along the timeline. Calling either method stops the playback and moves the playhead forward or backward one frame, respectively.

The

Use the Play () method is similar to calling NextFrame () whenever the Enterframe event of a movie clip object is triggered. Using this method, you can create an event listener for the Enterframe event and let bicycle return to the previous frame in the listener function, allowing the bicycle movie clip to play backwards, as follows:

  code is as follows copy code
// function is called the Enterframe event is triggered, meaning 
//It's called once per frame.
Function Everyframe (event:event): void
{
    if (bicycle.currentframe = 1)
     {
        bicycle.gotoandstop (bicycle.totalframes);
   }
    Else
    {
        Bicycle.prevframe ();
   }
}
Bicycle.addeventlistener (Event.enter_frame, everyframe);

During normal playback, if a movie clip contains more than one frame, the playback will loop endlessly, meaning that it will return to frame 1th after the last frame. This behavior does not occur automatically when you use Prevframe () or NextFrame () (The Call to Prevframe () when the playhead is in frame 1th does not move the playhead to the last frame). The IF condition in the preceding example checks that the playhead has returned to the first frame and sets the playhead to be in front of the last frame, effectively making the movie clip loop backward continuously.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.