Hello all,
I am trying to write some code for someone show wants to be able to control their timeline animation by using the slider component. Everything was going fine until I tried to add the Play and Pause buttons to the stage. I instantiated both movieclips and added "stage.addChild(<mcName>);" but neither clip showsup when I test the movie. I tried removing "stage." but that didn't help either.
I tried to find a solution to my problem online, and while I haven't figured it out yet, it seems that these movieclips might need to be part of a function. This could be totally incorrect, but it's the best guess I have right now.
Any help would be greatly appreciated. My AS code is below. (I couldn't get the .FLA file to zip small enough, but if anyone wants it, I'll find a way.) See comment "// PLAY/PAUSE CODE" for Play/Pause buttons.
Thanks,
Cindy
Code:
//SLIDER CODE
// Import slider and movieclip classes
import fl.controls.Slider;
import fl.events.SliderEvent;
import flash.display.MovieClip;
// Instantiate slider
var mcSlider:Slider = new Slider();
// Add slider to stage
addChild(mcSlider);
// Position slider
mcSlider.move(20,400);
// Set slider size
mcSlider.setSize(280,1);
// Determine slider incrememtal behavior
mcSlider.maximum = mcBall.totalFrames;
mcSlider.liveDragging = true;
// Make animation move in relation to slider
mcSlider.addEventListener(Event.CHANGE, updatemc)
function updatemc(event:Event)
{
mcBall.gotoAndStop(mcSlider.value)
} // end function updatemc
// Make slider nub match movieclip position
mcSlider.addEventListener(Event.ENTER_FRAME, matchFrames);
function matchFrames(event:Event):void
{
mcSlider.value = mcBall.currentFrame;
if(mcSlider.value == mcBall.currentFrame)
{
mcBall.play();
}
if(mcSlider.value == mcSlider.maximum)
{
mcBall.stop();
}
}
// PLAY/PAUSE CODE
// Instantiate buttons
var mcPlay:MovieClip = new MovieClip();
var mcPause:MovieClip = new MovieClip();
// Add Play and Pause buttons to stage
stage.addChild(mcPlay);
stage.addChild(mcPause);
// Position Play and Pause buttons to stage
mcPlay.x = 160;
mcPlay.y = 334;
mcPause.x = 160;
mcPause.y = 334;
// Make "Play" button invisible whie movieclip plays
mcPlay.visible = false;
mcPause.visible = true;
// Play/pause button functionality - Two functions
mcPause.addEventListener(MouseEvent.CLICK, pauseBall)
function pauseBall(event:MouseEvent):void
{
mcPlay.visible = true;
} // end function pauseBall
mcPlay.addEventListener(MouseEvent.CLICK, playBall)
function playBall(event:MouseEvent):void
{
mcPlay.visible = false;
} // end function playBall