Author Topic: Animation player  (Read 281 times)

Fello Muz   «   on: August 21, 2012, 08:07:58 AM »
Hi,
I created a player to start and stop an animation. Everything is good, the only thing I can't solve is how to update the position of the slider's knob. Here is the code I tried:

btn_play.addEventListener(MouseEvent.CLICK, play_klick);

function play_klick(event:MouseEvent):void{
    animation.play();
    scene.addEventListener( Scene3D.UPDATE_EVENT, update_pos );  
}

var vid_pos:int;  

function update_pos(e:Event):void{
    vid_pos = Math.round(animation.currentFrame * boundWidth / animation.frames.length + trackX);
    sliderKnob.x = vid_pos;
}

Can anybody help?

Ivan Vodopiviz   «   Reply #1 on: August 21, 2012, 10:12:57 AM »
Hi,

I wrote a small example, you can find it here. Please, try not to open new threads when you already posted your question in another one :)

Cheers,

Fello Muz   «   Reply #2 on: August 22, 2012, 07:06:37 AM »
Hi Ivan,
sorry, I thought the elder thread would be dead. Thanks for the example. I tried to fix my code, but now after more than an hour with trying I gave up. I don't get how this work with a play-button? Does the play-button have an own EventListener or is the function update_pos with the update function of the camera?

Ivan Vodopiviz   «   Reply #3 on: August 22, 2012, 11:48:50 AM »
Well, they should have different event listeners because they're two separate actions. The play button should listen to a CLICK event so you can play your animations and the slider knob should listen to the scene update event to keep the slider updated at the correct position. I didn't add a play button to my example because you were asking about the slider, and I had to write the example in a hurry.

Cheers,

Fello Muz   «   Reply #4 on: August 22, 2012, 06:03:57 PM »
Ok, so the play-button starts the animation by click and I added a listener to the knob like this:

sliderKnob.addEventListener( Scene3D.UPDATE_EVENT, update_knob );
function update_knob(e:Event):void{

    var currPercent:Number = (animation.currentFrame * 100) / animation.frames.length;
    var vid_pos:Number = (currPercent * boundWidth) / 100;
    sliderKnob.x = vid_pos + trackX;

}

Should this be ok? Sorry I can't fix it..?

Ivan Vodopiviz   «   Reply #5 on: August 23, 2012, 09:56:34 AM »
I can't really tell if that's right or not: I don't know what trackX and boundWidth are and I don't know which object is sliderKnob parented to.

The calculation itself seems right, though.

Fello Muz   «   Reply #6 on: August 23, 2012, 06:26:43 PM »
Well, sliderKnob is the knob inside the player which is addes as a child, trackX is the start of the slider and boundWidth is the width of the track.

I think the problem is that animation.frames.length and animation.currentFrame are not working.

How could it happen that frame calculation doesn't work?

P:S.: The code for integrating the animation is:

var animation:Pivot3D;
animation = scene.addChildFromFile ( "ani.f3d");
scene.addChild( animation );

Arun V   «   Reply #7 on: August 24, 2012, 02:02:40 AM »
Hi,
   If you use the Slider in flex then everything will be easy

just set the slider maximum to the total frames length

i.e.   slider.maximum=object.frames.length;

and in the update function update the slider position while playing the animation

i.e. slider.value=object.currentFrame;

this will update the slider position.

Hope this helps!  :)

Fello Muz   «   Reply #8 on: August 24, 2012, 06:56:00 AM »
Hello, thanks for reply. I build a custom slider/scrubber and do not use the slider class. This won't solve the problem with the calculation.

Fello Muz   «   Reply #9 on: August 27, 2012, 11:08:49 AM »
Hi Ivan,
now I added a Label to the Pivot3D like:
model.addLabel( new Label3D( "start1", 0, 50 ) );

I testet the length with model.labels["start1"].length - this works.
But when testing current frame with model.currentFrame, it always traces 0. How can I get the currentFrame?

Thx for help!!

Fello Muz   «   Reply #10 on: August 28, 2012, 06:38:09 PM »
Now I got it, really tricky with the mesh3d....