In my effort to build a gugga-powered version of dr promo site, I am
starting to code the simplest secitons, as classes derived from
gugga.application.Section. The most simple section uses an animation in
its own timeline to make the opening/closing animation. So, to build
the opening sequence, I need a task that does the following:
1) goes to a specified frame and plays;
2) when the animation stops (I used a stop() action in timeline to stop
it), it fires the 'completed' event.
Is there a Task that I can uses for that? Or, if not, how could I build
a Task class that plays an animation (in timeline) and fires the
'completed' event when the animation is stopped? I couldn't think about
anything better than the following:
- a Task class that has a member called m_mcTarget and another called
m_nStartFrame
- when the Task is activated, it executes
m_mcTarget.gotoAndPlay(m_nStartFrame);
- to detect when the animation stops, the Task could use some kind of
onEnterFrame function (where I compare the value of currentframe with
the previous value of currentframe), but I would like there was some
better way to do this.
what do you think about that? There are other sections that use
scrippted animations, but I think it would be nice if gugga had some
kind of 'timeline task' ;-)
bye,
andrei
please, look if the code below makes sense:
// SegmentedTimeLineAnimation
// What is the difference in relation to TimeLineAnimeation:
//
// - we needed a task that played only a fraction of a timeline;
// - TimeLineAnimation actually has cuePoints, but it cann't stop in a
cuePoint
// - we just added the possibility of setting a startingPoint and an
finalPoint to the task.
//
// and...@cappuccinohzta.com.br / andrei...@gmail.com
// 2006
//
import gugga.animations.IAnimation;
import gugga.collections.ArrayList;
import gugga.animations.TimeLineAnimation;
class SegmentedTimeLineAnimation extends
gugga.animations.TimeLineAnimation
{
private var mStartPoint:Number; // a frame number
private var mFinalPoint:Number;
function SegmentedTimeLineAnimation()
{
super();
mStartPoint = 0;
mFinalPoint = 0;
}
function setStartPoint( nStartPoint:Number ):Void
{
if (nStartPoint > 0)
mStartPoint = nStartPoint;
}
function setFinalPoint( nFinalPoint:Number ):Void
{
if (nFinalPoint > 0)
mFinalPoint = nFinalPoint;
}
function setStartFinalPoint( nStartPoint:Number, nFinalPoint:Number
):Void
{
setStartPoint(nStartPoint);
setFinalPoint(nFinalPoint);
}
// functions of TimeLineAnimation that we override
// - start
// - onEnterFrameHandler
public function start():Void
{
if (!mIsRunning)
{
mIsRunning = true;
dispatchEvent({type:"start", target:this});
if (mStartPoint > 0)
gotoAndStop(mStartPoint);
else
gotoAndStop(1);
show();
this.play();
}
}
public function onEnterFrameHandler()
{
if (!mIsRunning)
{
this.onEnterFrame = null;
return;
}
// final point
if (this._currentframe == mFinalPoint) {
onAnimationCompleted();
}
for(var i:Number = mCuePoints.length - 1; i >= 0; i--)
{
if(this._currentframe >= mCuePoints[i].position)
{
dispatchEvent({type:mCuePoints[i].event, target:this});
break;
}
}
if (!this.mDoLoop)
{
if(this._currentframe == this._totalframes)
{
onAnimationCompleted();
}
}
}
}
I studied the code of TimeLineAnimation, to implement the
PartialAnimation class, and I am with a doubt: how do you set the scope
of the animation, in the case of it being used as a task? Because:
a) I could associate the movie clip, whose timeline I want to control
with PartialAnimation class, with a class derived from
PartialAnimation. Problem: how to make this class also derived of
Section class ?
b) Or pass the object's scope to the instance of PartialAnimation that
will be the section opening's task (as it is done in ExecuteMethodTask,
for example).
I am in doubt because I don't understand why the PartialAnimation would
receive a IAnimation-derived object in the constructor. For what I
could understand, it should receive the object to be animated (as in
ExecuteMethodTask).
thanks for your time,
andrei