This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
Relevant code follows:
var animLength : int = ballAnimationMC.totalFrames;
var leftBound : Number = scrubberMC.scrubBarMC.x;
var rightBound : Number = scrubberMC.scrubBarMC.x scrubberMC.scrubBarMC.width;
var dragBound : Rectangle = new Rectangle(leftBound, scrubberMC.scrubHandleMC.y, scrubberMC.scrubBarMC.width, 0);
var calcWidth : Number = scrubberMC.scrubBarMC.width / animLength;
var animPlaying : Boolean = false;
ballAnimationMC.gotoAndStop(1);
frameTxt.text = String(ballAnimationMC.currentFrame);
scrubberMC.scrubHandleMC.x = leftBound;
scrubberMC.scrubHandleMC.buttonMode = true;
scrubberMC.scrubHandleMC.addEventListener(MouseEvent.MOUSE_DOWN, handleMouseEvents);
toggleBtn.label = "Play Animation";
toggleBtn.addEventListener(MouseEvent.CLICK, togglePlay);
function handleMouseEvents(evt:MouseEvent):void
{
switch(String(evt.type)) {
case MouseEvent.MOUSE_DOWN:
scrubberMC.scrubHandleMC.startDrag(false, dragBound);
stage.addEventListener(MouseEvent.MOUSE_UP, handleMouseEvents);
ballAnimationMC.addEventListener(Event.ENTER_FRAME, scrubMovie);
break;
case MouseEvent.MOUSE_UP:
scrubberMC.scrubHandleMC.stopDrag();
stage.removeEventListener(MouseEvent.MOUSE_UP, handleMouseEvents);
ballAnimationMC.removeEventListener(Event.ENTER_FRAME, scrubMovie);
break;
}
}
function scrubMovie(evt:Event):void
{
var scrubPos : int = scrubberMC.scrubHandleMC.x;
var gotoFrame : int = Math.ceil(scrubPos / calcWidth);
ballAnimationMC.gotoAndStop(gotoFrame);
frameTxt.text = String(ballAnimationMC.currentFrame);
}
function togglePlay(evt:MouseEvent):void { if (!animPlaying) { ballAnimationMC.play(); animPlaying = true; toggleBtn.label = "Stop Animation"; scrubberMC.addEventListener(Event.ENTER_FRAME, updateScrubber);
// DISABLE SCRUBBER INTERACTION WHILE ANIMATION PLAYS
scrubberMC.mouseChildren = false;
} else {
ballAnimationMC.stop();
animPlaying = false;
toggleBtn.label = "Play Animation";
scrubberMC.removeEventListener(Event.ENTER_FRAME, updateScrubber);
// ENABLE SCRUBBER INTERACTION AFTER ANIMATION STOPS
scrubberMC.mouseChildren = true;
}
}
function updateScrubber(evt:Event):void { var percent : Number = ballAnimationMC.currentFrame / animLength; scrubberMC.scrubHandleMC.x = percent * scrubberMC.scrubBarMC.width;
frameTxt.text = String(ballAnimationMC.currentFrame);
}
I'm looking to be able to create points where once the user gets to specific point in the timeline, the scrubber will require them to release the mouse button, then start dragging again.
Any ideas?
Thanks in advance for your help.
Subreddit
Post Details
- Posted
- 12 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/flash/comme...