Playing a movie clip to its full with mouse over

381 views Asked by At

In Adobe Flash and ActionScript 3.0, I have a movieclip within a button. I want to play the entire movie clip upon mouse over. However, the movieclip plays only untill the mouse is over. I want to play the movie clip till the end if the mouse was there.

Any help is appreciated. I found a blog but, it is valid for AS2 only. This is what I want to do, but with AS3 : EchoEcho

I am a noob for flash and I dont know what to share for this kind of problem. I will provide anything that is needed for solving the problem

Thanks

1

There are 1 answers

0
tatactic On BEST ANSWER

To make it simple... If you have an instance named "your_mc" that contains your animation (a MC named your_symbol in the library and you have a tween in the instance named "your_mc"

If the MovieClip is placed on the stage, You may try this.

import flash.display.MovieClip;
import flash.events.MouseEvent;

var your_mc:MovieClip = your_mc;
your_mc.stop()
var clipStopped:Boolean = true;
your_mc.addEventListener(MouseEvent.MOUSE_OVER,playStopClip);
your_mc.addEventListener(MouseEvent.MOUSE_OUT,playStopClip);
function playStopClip(e:MouseEvent):void{
    switch (clipStopped) {
        case false:
            clipStopped = !clipStopped;
            break;
        case true:
            clipStopped = !clipStopped;
            break;
    }
    if (!clipStopped){
        your_mc.gotoAndPlay(1);
    }else{
        your_mc.gotoAndStop(1);
    }
}

Be careful this is not Class Based, and should be considered as a basic example! If You want something more specific, please, edit Your question!

Really basic example here:

fla file

swf file

This is not clean, so, just edit Your question if You want something more efficient please. If you want to play the entire MovieClip, just check MC.currentFrame and MC.total frames and add a Boolean value to check this. So the MC cannot stop before the end of the animation.

Best regards. Nicolas

[EDIT] This will play Your MovieClip to the end when the Mouse is over...

import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;

var isRunning:Boolean = false;
var your_mc:MovieClip = your_mc;
your_mc.stop()
var clipStopped:Boolean = true;
your_mc.addEventListener(MouseEvent.MOUSE_OVER,playStopClip);

function playStopClip(e:MouseEvent):void{
    if(clipStopped && isRunning==false){
        trace("is Running = " + !isRunning)
            your_mc.gotoAndPlay(1);
            clipStopped = !clipStopped;
            isRunning = true
            your_mc.addEventListener(Event.ENTER_FRAME,changeStatus);
    }
}
function changeStatus(e:Event):void{
    if (your_mc.currentFrame == your_mc.totalFrames){
        isRunning = false;
        clipStopped = true;
        your_mc.gotoAndStop(1);
        your_mc.removeEventListener(Event.ENTER_FRAME,changeStatus);
    }
    trace(your_mc.currentFrame + " / " + your_mc.totalFrames);
}

fla file

swf file

import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;

var isRunning:Boolean = false;
var your_mc:MovieClip = your_mc;
your_mc.stop()
var clipStopped:Boolean = true;
your_mc.addEventListener(MouseEvent.MOUSE_OVER,playStopClip);

function playStopClip(e:MouseEvent):void{
    if(clipStopped && isRunning==false){
        trace("is Running = " + !isRunning)
            your_mc.gotoAndPlay(1);
            clipStopped = !clipStopped;
            isRunning = true
            your_mc.addEventListener(Event.ENTER_FRAME,changeStatus);
    }
}
function changeStatus(e:Event):void{
    if (your_mc.currentFrame == your_mc.totalFrames){
        isRunning = false;
        clipStopped = true;
        your_mc.stop();
        your_mc.removeEventListener(Event.ENTER_FRAME,changeStatus);
    }
    trace(your_mc.currentFrame + " / " + your_mc.totalFrames);
}

fla file

swf file

No more MouseEvent.MOUSE_OUT here if you want to play Your Movie Clip to the last frame.

The MouseEvent.MOUSE_OVER is only available when Your Movie clip animation is completed.

So as You didn't give feedback and the question is unclear : "DownVote"

[/EDIT]