Question

I'm new in games development, am trying to create a simple game in flash-cs5. I created 3 motion tweens in timeline. i'm trying to stop a specific motion tween, when that tween's movieclip is clicked while other tweeens are running and also when the stopped movieclip is clicked again i want to resume the tween while other tweeens are running.

thanking in advanced.

Was it helpful?

Solution

The following is assuming you have each motion tween inside its own movieclip. I am not aware of any method of stopping one tween while leaving the other playing on a single movieclip (or if they are each on the main stage).

That said, you can stop and start animations fairly easily. Below is an example of how to stop a motion tween where it is in playback, and then resume it from that point.

In the example, "myMovieClip" is the movie clip we're working with. We're going to leave the rest of the movieclips alone, as they'll keep playing on their own. I'm also assuming that myMovieClip is playing by default.

The following is in AS3. Place it on the Actions panel for your main stage (first frame if you have multiple frames.)

Also, ensure you have named your MovieClip. To do this, click the MovieClip on your stage in design mode, and then click Properties. There should be a text entry box towards the box. Write the name you want for your MovieClip there.

//Declare a boolean variable that determines whether or not the movieclip timeline is playing.
var ClipPlaying:Boolean = true;

//Add the mouse click event listener to the movie clip.
myMovieClip.addEventListener(MouseEvent.CLICK, StopOrStartClip);

//Declare the function for the above event listener.
function StopOrStartClip(evt:MouseEvent):void
{
    //Switch statements are my personal favorites...they're more streamlined than if statements.
    switch(ClipPlaying)
    {
        //If the clip is playing it, we stop it and set ClipPlaying to false.
        case true:
            myMovieClip.stop();
            ClipPlaying = false;
        break;
        //If the clip is not playing, we start it and set ClipPlaying to true.
        case false:
            myMovieClip.play();
            ClipPlaying = true;
        break;
    }
}

The most important functions to remember here are:

myMovieClip.stop();

This freezes your animation at its current position.

myMovieClip.play();

This resumes your animation playback from its current position.

When you use either, remember to replace "myMovieClip" with the name of your movie clip!

By the way, slightly unrelated, I highly recommend the book ActionScript 3.0 Game Programming University to learn how to create Flash games.

OTHER TIPS

You wouldn't actually need 5 different event listeners, or functions, or variables; you could just make one function to handle it all:

stage.addEventListener(MouseEvent.CLICK, stageClick);

function stageClick(event:MouseEvent):void {

//I prefer "if" statements

if (event.target == myMovieClip1) stuff here;
else if (event.target == myMovieClip2) stuff here;
else if (event.target == myMovieClip3) stuff here;
else if (event.target == myMovieClip4) stuff here;
else if (event.target == myMovieClip5) stuff here;

}

I can add more details if needed, but this question was from three years ago so probably not.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top