Maintenance - We're currently working on things and you might experience some issues. Should be wrapped up soon!

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.

1
Help with creating sticky or stopping points with an AS3 timeline scrubber.
Post Body

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.

Author
Account Strength
100%
Account Age
16 years
Verified Email
Yes
Verified Flair
No
Total Karma
32,751
Link Karma
1,968
Comment Karma
30,624
Profile updated: 2 days ago
Posts updated: 2 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
12 years ago