A reader requested a very simple solution for moving text so I decided to respond with this short tutorial on using the caurina Tweener library to move a block of text. (To repeat tween reload page.)
The code below uses the HTMLText class to create the block of text. In the example below without a transition type specified the default motion is linear.
// import required classes import com.dtk.HTMLText; import caurina.transitions.*; // create block of text (see documentation in class for description of parameters var t:HTMLText = new HTMLText( 200, 'Arial', 60, 0x006699, 'LEFT', 'TEXT' ); t.x = 10; t.y = 0; t.name = 't'; addChild( t ); // tween text block (sprite named 't' 340 pixels to the right Tweener.addTween( getChildByName( 't' ), { x: 340, time: 2 } ); |
In the above code no transition type is specified and, therefore, defaults to easeOutExpo; there is a wide range of transitions available from linear to spring and bounce. In addition, a function can be fired at the completion of a tween with the onComplete parameter as seen in the snippet below.
Tweener.addTween( getChildByName( 't' ), { x: 340, time: 2, transition: easeInOutSine, onComplete: onTweenCompleted } ); function onTweenCompleted( ):void { // do something else here after the tween is completed } |
Explore the documentation of Tweener in more detail here.
Download files: TextTween.zip (120)
Thanks for this tutorial
I’ve got a problem with the transition :
1120: Accès à la propriété non définie easeInOutSine.
I forgot to use the “” :
“easeInOutSine”
It works now