FlowText - with Flupie and Tweensy
/**
* Copyright tjoen ( http://wonderfl.net/user/tjoen )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/nUPG
*/
package
{
import flash.display.Sprite;
import flash.events.*;
import flash.events.MouseEvent;
import flash.utils.setTimeout;
import flash.display.*;
import flash.filters.*
import flash.geom.ColorTransform;
import flash.text.TextFormatAlign;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.geom.Point;
import flupie.textanim.*;
import com.flashdynamix.motion.*;
import com.flashdynamix.motion.effects.*;
import com.flashdynamix.motion.effects.core.*;
import com.flashdynamix.motion.layers.BitmapLayer;
import com.flashdynamix.motion.guides.Bezier2D;
import com.flashdynamix.utils.*;
import fl.motion.easing.*;
import net.wonderfl.utils.FontLoader;
[SWF(width="460", height="460", backgroundColor = '0x000000', frameRate="60")]
public class textanim_tweensy_01 extends Sprite
{
public var myAnim:TextAnim;
public var tween:TweensyGroup;
public var layer:BitmapLayer;
public var layer2:BitmapLayer;
public var holder:Sprite;
public var pdFx:PerlinDisplacementEffect;
public var fFx:FilterEffect;
public var cFx:ColorEffect;
public var tf:TextField;
public var _fm:TextFormat;
public var text_array:Array;
public var _i:Number = 0;
public var splitArray:Array = new Array();
public function textanim_tweensy_01()
{
var _canvas:Sprite = new Sprite();
_canvas.graphics.beginFill(0x000000);
var _canvasWidth:Number = stage.stageWidth;
var _canvasHeight:Number = stage.stageHeight;
_canvas.graphics.drawRect(0, 0, _canvasWidth, _canvasHeight);
_canvas.graphics.endFill();
//addChild(_canvas);
var fl :FontLoader = new FontLoader;
fl.load( "IPAGP" );
fl.addEventListener( Event.COMPLETE, function(ev :Event) :void {
text_array = new Array();
text_array = [
"Tweensy <b><font size =\"+10\">&</font></b> Flupie\n<font size =\"-5\">Nice Text Tweeneffects!!</font>",
"FLASH\n<font size =\"+60\" color=\"#fff000\">(AHA)</font>\nSaviour of the universe",
"I'm <b>Not A Number</b>,\ncan't you see?",
"<font size =\"+90\">BIG</font>\nin Japan",
"TEXT ANIM\n<font size =\"+60\">AS3</font>\nrocks",
"It's <font color=\"#FFFFFF\">Wonder</font><font color=\"#FF0000\">FL</font><br>",
"<center><font size =\"-10\">NOW STOP</font><br><font size =\"+60\" color=\"#ff0000\">IT</font><br><font size =\"+10\">TJOEN!!!</font></center>"];
tf = new TextField;
tf.embedFonts = true;
tf.autoSize = "center";
tf.multiline = true;
addChild(tf);
splitArray = ["CHARS", "WORDS"]; // "LINES" is not so cool
myAnim = new TextAnim(tf);
myAnim.htmlText = text_array[_i];
myAnim.mode = TextAnimMode.RANDOM;
myAnim.interval = 50;
myAnim.blocksVisible = false;
myAnim.effects = myEffect1;
myAnim.split = splitArray[getRandom(0,1)];
myAnim.x = 180;
myAnim.y = 200;
tween = new TweensyGroup(false, true, Tweensy.FRAME);
tween.secondsPerFrame = 1 / 8;
layer2 = new BitmapLayer(460, 460, 2);
layer2.smoothing = false;
addChild(layer2);
layer2.draw(_canvas);
layer = new BitmapLayer(460, 460, 3);
layer.smoothing = true;
addChild(layer);
holder = new Sprite();
pdFx = new PerlinDisplacementEffect(_canvasWidth, _canvasHeight, 1, -2, 2);
fFx = new FilterEffect(new BlurFilter(0.5, 1, 1.5));
cFx = new ColorEffect(new ColorTransform(0.98, 0.88, 0.1, 1));
layer.add(fFx);
layer.add(cFx);
layer.draw(holder);
var gf : GlowFilter = new GlowFilter(0xCC00CC, .5, 4, 4, 1, 1, false, false);
//layer.filters = [gf];
// CLICK TO START BUTTON
holder.buttonMode = true;
holder.addEventListener(MouseEvent.CLICK, _clickStart, false, 0, true);
//first clicky!
holder.dispatchEvent(new MouseEvent(MouseEvent.CLICK,true));
});
}
public function myEffect1(block:TextAnimBlock):void
{
var ct : ColorTransform = new ColorTransform();
ct.redOffset = 50 + (125 * Math.random());
ct.greenOffset = 150 + (50 * Math.random());
block.transform.colorTransform = ct;
block.alpha = 0;
block.scaleX = block.scaleY = 0;
block.x = getRandom( -stage.width, 2 * stage.width);
block.y = getRandom(-stage.height, 2*stage.height);
tween.to(block, { alpha:1, scaleX:1, scaleY:1, x:block.posX, y:block.posY }, 5, Back.easeOut);
var tween1:TweensyGroup = new TweensyGroup();
var bezier:Bezier2D = new Bezier2D(block, true, false, false );
bezier.push(new Point(block.posX, block.posY));
bezier.push(new Point(block.posX + getRandom(-10, 10), block.posY + getRandom(-10, 10)));
bezier.push(new Point(block.posX + getRandom(-10, 10), block.posY + getRandom(-10, 10)));
bezier.push(new Point(block.posX + getRandom(-10, 10), block.posY + getRandom(-10, 10)));
bezier.push(new Point(block.posX, block.posY));
tween1.to(bezier, { position:1 }, 4, Sine.easeInOut,5);
}
public static function getRandom(min_num:Number,max_num:Number):Number{
return min_num + Math.floor(Math.random() * (max_num + 1 - min_num));
}
public function _clickStart(e:MouseEvent):void
{
Tweensy.to(layer2.transform.colorTransform, { redOffset: Math.random() * 100, greenOffset: Math.random() * 100, blueOffset:Math.random() * 100 }, 5, null, 0, layer2);
myAnim.split = splitArray[getRandom(0,1)];
_fm = new TextFormat("IPAGP", getRandom(30, 44), Math.random() * 0xffffff, true);
_fm.align = TextFormatAlign.CENTER;
tf.defaultTextFormat = _fm;
myAnim.blocksVisible = false;
layer.remove(pdFx);
layer.add(pdFx);
holder.addChild(myAnim);
//This start textanim
myAnim.htmlText = text_array[_i];
myAnim.start();
if ( _i == text_array.length - 1 ) _i = 0;
else { _i ++};
setTimeout(function():void {
holder.dispatchEvent(new MouseEvent(MouseEvent.CLICK,true));
}, 16000);
}
}
}