forked from: flash on 2009-6-24
/**
* Copyright taka_milk ( http://wonderfl.net/user/taka_milk )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/jQJL
*/
// forked from gabriel_laet's flash on 2009-6-24
package {
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.TextFieldAutoSize;
import flash.display.BitmapData;
import flash.display.BitmapDataChannel;
import flash.display.Bitmap;
import caurina.transitions.Tweener;
public class FlashTest extends Sprite {
public var words:Array;
public var wordsBmp:Array;
public var container:Sprite;
public function FlashTest() {
stage.align = "tl";
stage.scaleMode = "noScale";
words = ["paz", "fé", "vida", "mundo", "hoje", "pensamento"];
wordsBmp = [];
container = new Sprite();
addChild(container);
draw();
}
public function draw():void
{
var fmt:TextFormat = new TextFormat();
fmt.size = 30;
fmt.font = "Arial";
fmt.bold = true;
var temp:TextField = new TextField();
temp.autoSize = TextFieldAutoSize.LEFT;
temp.defaultTextFormat = fmt;
var word:BitmapData;
var display:Bitmap;
for(var i:int = 0; i<words.length; i++){
temp.text = words[i];
word = new BitmapData(temp.width, temp.height, true, BitmapDataChannel.ALPHA);
word.draw(temp);
display = new Bitmap(word);
container.addChild(display);
Tweener.addTween(display, {x:Math.max(0,Math.min(stage.stageWidth, Math.random()*stage.stageWidth)), y:Math.max(0,Math.min(stage.stageHeight, Math.random()*stage. stageHeight)), time:Math.random()*10, rotation:Math.random()*360});
wordsBmp.push(display);
}
addEventListener("enterFrame", render);
}
public function render(e:*):void
{
var b:Bitmap;
container.graphics.clear();
container.graphics.lineStyle(1, 0x999999);
for(var i:int = 0; i<wordsBmp.length; i++){
b = wordsBmp[i];
if(!Tweener.isTweening(b)){
Tweener.addTween(b, {x:Math.random()*stage.stageWidth, y:Math.random()*stage.stageHeight, time:30+Math.random()*30});
}
if(wordsBmp[i+1]){
container.graphics.lineTo(wordsBmp[i+1].x, wordsBmp[i+1].y);
}else{
container.graphics.lineTo(wordsBmp[0].x, wordsBmp[0].y);
}
}
}
}
}