Flup-a-click
/**
* Copyright tjoen ( http://wonderfl.net/user/tjoen )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/w2ES
*/
package {
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.text.TextFormatAlign;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.filters.GlowFilter;
import flash.filters.DropShadowFilter;
import flash.filters.BitmapFilterQuality;
import flupie.textanim.*;
import caurina.transitions.Tweener;
import caurina.transitions.properties.*;
import net.wonderfl.utils.FontLoader;
public class FlupieTest extends Sprite {
[SWF(width = '465', height = '465', backgroundColor = '0x353436', frameRate = '60')]
public var _canvas:Sprite;
private var _canvasWidth:int;
private var _canvasHeight:int;
public var outline:GlowFilter
public var ds:DropShadowFilter;
public var tf:TextField;
public var _click:Boolean = false;
public var _fm:TextFormat;
public function FlupieTest() {
_canvas = new Sprite();
addChild(_canvas);
_canvas.graphics.beginFill(0x353436);
_canvasWidth = stage.stageWidth;
_canvasHeight = stage.stageHeight;
_canvas.graphics.drawRect(0, 0, _canvasWidth, _canvasHeight);
_canvas.graphics.endFill();
addEventListener(MouseEvent.CLICK, onClick);
var fl :FontLoader = new FontLoader;
fl.load( "Mona" );
fl.addEventListener( Event.COMPLETE, function(ev :Event) :void {
RunText();
});
}
public function RunText():void {
var text_array:Array = new Array();
text_array = [
"Just <font size =\"-5\">Another</font> FlupieTest\n<font color=\"#FF0000\">-</font><font color=\"#00FF00\">=</font><font color=\"#0000FF\">+</font><font color=\"#FFFF00\">*</font><font color=\"#FFFFFF\">#</font><font color=\"#FFFF00\">*</font><font color=\"#0000FF\">+</font><font color=\"#00FF00\">=</font><font color=\"#FF0000\">-</font>\nI'm so sorry!",
"FLASH\n<font size =\"+70\" color=\"#fff000\">(AHA)</font>\nSaviour of the universe",
"I'm Not A Number,\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 =\"+20\">NOW</font><br>STOP<br><font size =\"+60\" color=\"#ff0000\">IT</font><br><font size =\"+10\">TJOEN!!!</font></center>"];
var whatText:Number = Math.round (Math.random () * (text_array.length - 1));
_fm = new TextFormat("Mona", getRandom(22,42), Math.random() * 0xffffff, true);
_fm.align = TextFormatAlign.CENTER;
tf = new TextField;
tf.embedFonts = true;
tf.autoSize = "center";
tf.multiline = true;
tf.defaultTextFormat = _fm;
addChild(tf);
outline = new GlowFilter();
outline.blurX = outline.blurY = 2;
outline.color = 0x000000;
outline.quality = BitmapFilterQuality.HIGH;
outline.strength = 50;
ds = new DropShadowFilter( 4, 45, 0X000000, 1, 2.0, 2.0, 1.0, 1);
var filterArray:Array = new Array();
filterArray.push(outline, ds);
tf.filters = filterArray;
var splitArray:Array = new Array();
splitArray = ["CHARS", "WORDS", "LINES"];
var anim:TextAnim = new TextAnim(tf);
anim.htmlText = text_array[whatText];
anim.effects = myEffect;
anim.mode = TextAnimMode.RANDOM;
anim.blocksVisible = false;
anim.split = splitArray[getRandom(0,2)];
anim.blocksVisible = false;
if ( _click == false ) {
anim.x = _canvasWidth / 2 - anim.width / 4;
anim.y = _canvasHeight / 2 - anim.height / 2;
}
else {
anim.x = mouseX - anim.width / 4;
anim.y = mouseY - anim.height;
}
anim.start();
init();
}
private function myEffect(block:TextAnimBlock):void {
block.scaleX = block.scaleY = 0;
//block.rotation = getRandom(-80,80); more chaotic!
block.y = block.posY - getRandom(200,1500);
Tweener.addTween(_canvas, { _color:Math.random()*0xFFFFFF, time:2, transition:"linear", delay:0});
Tweener.addTween(block, { rotation:0, y: block.posY, x: block.posX, scaleX:1, scaleY:1, time:2, transition:"easeoutelastic" } );
Tweener.addTween(block, { alpha: 0, rotation:0, scaleX:0, scaleY: 0, y:block.posY+getRandom(-1000,1000), x:block.posX+getRandom(-1000,1000), scaleX:1, scaleY:1, time:3, transition:"linear", delay:7 } );
}
public static function init():void {
ColorShortcuts.init();
DisplayShortcuts.init();
FilterShortcuts.init();
}
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 onClick(event:MouseEvent):void {
// add extra events if you like
Tweener.addTween(_canvas, { _color:Math.random()*0xFFFFFF, time:3, transition:"linear", delay:6});
_click = true;
RunText();
}
}
}