There are times that you might loss some interests in AS because of less works related and want to learn new stuffs like iPhone development, Sliverlight etc…

To keep things interesting during downtime, I have found that writing your own framework or engine can just do that. Also the benefit is that you can improve the skill further.

So introducing Domo (DO MOtion) motion tween engine, my useful tween engine that does common motion tasks plus more:)

As you may have used some of popular tween engines so I have tried to use similar API/parameters approaches to keep the familiarities, below are some nuts and bolts of Domo engine:

Domo has static “addMotion()” method that you can add new tween with 3 parameters, 3rd one is optional:

?View Code ACTIONSCRIPT
1
2
3
// Move myTarget from current position to (100, 100) during 2 seconds
// with ease function Elastic.easeIn.
Domo.addMotion(myTarget, {duration:2, x:100, y:100, ease:Elastic.easeIn});

1st parameter is your target object, it can be any objects like Sprite, MovieClip etc…, 2nd parameter is where all tween and object properties are.

Here are current list of optional properties in 2nd parameter: duration, useFrames, delay, ease, onInit, onInitParams, onUpdate, onUpdateParams, onComplete, onCompleteParams.

So if you want to delay the object by 1 second and call a function during the motion, you can do like:

?View Code ACTIONSCRIPT
1
2
3
4
5
Domo.addMotion(myTarget, {duration:2, delay:1, x:100, y:100, ease:Elastic.easeIn, onUpdate:myUpdate, onUpdateParams:["hello!"]});
 
function myUpdate(a:String):void {
	trace(a);
}

3rd parameter is mode/type of tweens, kind of like extensions or plugins. I have added 3 extensions so far, 1st one is default object tween (Domo.OBJECT), 2nd one is filter (Domo.FILTER) and 3rd one is typo motion (Domo.TYPO) which is a bit different from the first 2 extensions, will come more info in the next post.

If you want to tween filter, there is one more extra property “filterIndex” in 2nd parameter to indicate the filter index you want to tween, default to 0:

?View Code ACTIONSCRIPT
1
2
// Assume myTarget has blur filter applied at index 0.
Domo.addMotion(myTarget, {duration:2, filterIndex:0, blurX:10, blurY:10, quality:2, ease:Elastic.easeIn}, Domos.FILTER);

You can also use instance base like other classes:

?View Code ACTIONSCRIPT
1
2
3
4
5
6
7
8
var domo:Domo = new Domo(myTarget, {duration:2, x:100, y:100, ease:Elastic.easeIn});
 
// And you can also add listener to it.
domo.addEventListener(DomoEvent.UPDATE, onDomoUpdate);
 
function onDomoUpdate(e:DomoEvent):void {
	trace(e.target);	
}

Of course, you can call “pause(), resume(), stop(), stopAll()” methods on them, also they will become garbage collectable once the motion has finished.

I will try to add some more functions or bug fixing and post the swc for you to try out in next few days if nothing keeps me busy:)