-
1. Re: stop a movieclip
SantoshBhagat Dec 25, 2011 10:26 PM (in response to cactus8599)//Replace you first frame code with these
import flash.display.*;
import flash.events.*;
var hero:Hero = new Hero();
hero.x = 100;
hero.y = 200;
addChild(hero);
var stopBtn:btn = new btn();
stopBtn.x = 215;
stopBtn.y = 270;
addChild(stopBtn);
// added a play button for animation
var playBtn:btn = new btn();
playBtn.x = 300;
playBtn.y = 270;
addChild(playBtn);
// it will tell me wheather the v is walking or standing
var heroState:String = "walking";
addEventListener(Event.ENTER_FRAME, animateHero);
function animateHero(evt:Event)
{
//depending on the char state it will react if state is stand it will stop and return
if (heroState == "stand")
{
hero.stop();
return;
}
//hero.x++;
//character should move 7 pixels per frame
hero.x += 7;
//continue to snimate until it reaches frame 8 (last frame in hero animation and go back to frame 2
if (hero.currentFrame == 8)
{
//frame 1 is not used because frame 1 is a standing position, reserved for not walking, so start from frame 2
hero.gotoAndStop(2);
}
else
{
//continue walking, going to frame 3,4,5...after looping
hero.gotoAndStop(hero.currentFrame+1);
}
if (hero.x > 580)
{
hero.x=-20
}
}
// on click of the button i am just setting the state to the character
stopBtn.addEventListener(MouseEvent.CLICK,stopAnimation);
function stopAnimation(evt:MouseEvent)
{
heroState = "stand";
}
playBtn.addEventListener(MouseEvent.CLICK,playAnimation);
function playAnimation(evt:MouseEvent)
{
heroState = "walking";
hero.play();
}
-
2. Re: stop a movieclip
cactus8599 Dec 26, 2011 12:32 AM (in response to SantoshBhagat)thank you for your help ;-)
