Author Topic: Animation Control  (Read 188 times)

Fello Muz   «   on: July 13, 2012, 06:33:20 AM »
Hello,
I have a problem with 2D buttons. In my project I started with a play button which starts the animation when it is clicked - this worked. Now a slider was integrated which controls the animation by dragging the knob of the slider - this worked as well. But unfortunately when the slider was integrated, the play button didn't work any longer. Why does this happen, where is the problem??

Ivan Vodopiviz   «   Reply #1 on: July 13, 2012, 10:08:55 AM »
Hi,

Without a code example or more details I can't be really sure, but maybe you're calling gotoAndStop in an update method? The one that keeps the slider updated maybe? Be careful not to call gotoAndPlay and gotoAndStop at the same time. If you can't figure it out, please send us a small code snippet so we might take a better look.

Cheers,

Fello Muz   «   Reply #2 on: July 13, 2012, 12:54:51 PM »
I think you're right, the problem is about play() in the play button and the gotoAndStop() in the enterframe. How could this be solved? Maybe you could help me with the code:

// Play-button
btn_play.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);
function fl_MouseClickHandler(event:MouseEvent):void
{
MovieClip(root).3D_action.play();
}

// Slider
sliderKnob.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
function startDragging(event:MouseEvent):void{
    sliderKnob.startDrag(false, boundsRect);
}

sliderKnob.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
sliderKnob.addEventListener(MouseEvent.MOUSE_OUT, stopDragging);
function stopDragging(event:MouseEvent):void{
    sliderKnob.stopDrag();
}

// Animation-control
sliderKnob.addEventListener(Event.ENTER_FRAME, onEnterFrameDown);
function onEnterFrameDown(event:Event):void {
    scrubMovie();
}

function scrubMovie():void {
    frame = Math.round(sliderKnob.x * frameFactor);
    MovieClip(root).3D_action.gotoAndStop(frame);
}

Ivan Vodopiviz   «   Reply #3 on: July 16, 2012, 10:33:42 AM »
Hi,

I don't quite understand a few things of the code, but for starters, I'd only perform the seek function (scrubMovie?) during the slider knob event listener, not during enterframe. Keep in mind that the enterframe event is triggered each frame, so you're stopping your animation all the time. Try to move that code into stopDragging.

Cheers,

Fello Muz   «   Reply #4 on: August 16, 2012, 09:39:00 AM »
Hello Ivan,

thanks for your reply. I made some modifications and now both things work, the animation starts when click on play-button and the control of the animation with the slider works.

But still there is one problem to solve: When the animations is startet, the knob of the slider should move according to the position in the animation. Here is the code, I tried:


btn_play.addEventListener(MouseEvent.CLICK, play_klick);

function play_klick(event:MouseEvent):void{

    3D_animation.play();
    scene.addEventListener( Scene3D.UPDATE_EVENT, update_pos );
   
}

var vid_pos:int;   

function update_pos(e:Event):void{

    vid_pos = Math.round(modell.currentFrame * boundWidth / modell.frames.length + trackX); 
    sliderKnob.x = vid_pos;

}

Why doesn't it work?   

Fello Muz   «   Reply #5 on: August 16, 2012, 09:41:37 AM »



               
                  
                     "Hello Ivan,

thanks for your reply. I made some modifications and now both things work, the animation starts when click on play-button and the control of the animation with the slider works.

But still there is one problem to solve: When the animations is startet, the knob of the slider should move according to the position in the animation. Here is the code, I tried:


btn_play.addEventListener(MouseEvent.CLICK, play_klick);

function play_klick(event:MouseEvent):void{

    3D_animation.play();
    scene.addEventListener( Scene3D.UPDATE_EVENT, update_pos );
   
}

var vid_pos:int;   

function update_pos(e:Event):void{

    vid_pos = Math.round(modell.currentFrame * boundWidth / modell.frames.length + trackX); 
    sliderKnob.x = vid_pos;

}

Why doesn't it work?   "
                     Fello M.
                  

               
               

this is of course:
modell.play();