forked from: asahi.com ぱーてぃくる
// forked from nitoyon's asahi.com ぱーてぃくる
// forked from munegon's ぱーてぃくる
// write as3 code here..
package {
import flash.display.*;
import flash.events.*;
import flash.geom.*;
import flash.net.*;
import flash.text.*;
public class BulletDemo extends Sprite {
private var URL:String = "http://pipes.yahooapis.com/pipes/pipe.run?_id=cEreGvJi3BG2_zgYxQnzeQ&_render=rss&url=http%3A%2F%2Fwww.asahi.com%2F";
private var text:String;
private var textIndex:int = 0;
private var SPEED_FO:Number = 0.8;
private var canvas_bd:BitmapData;
private var ctf:ColorTransform;
private var tf:TextFormat;
private var temp:Sprite;
public function BulletDemo () {
tf = new TextFormat();
tf.size = 16;
tf.bold = true;
var req:URLRequest = new URLRequest(URL);
var loader:URLLoader = new URLLoader();
loader.addEventListener("complete", function(event:Event):void{setup(loader.data);});
loader.addEventListener("ioError", function(event:Event):void{log("load error!!!");});
loader.addEventListener("securityError", function(event:Event):void{log("sec error!!!");});
loader.load(req);
}
private function log(msg:String):void{
var text:TextField = new TextField();
text.text = msg;
addChild(text);
}
private function setup(data:Object):void {
var xml:XML = XML(data);
if(!xml){ log(data.toString()); return;}
text = xml..item.title.text().toString();
canvas_bd = new BitmapData( stage.stageWidth, stage.stageHeight, false, 0x000000 );
addChild( new Bitmap( canvas_bd ) );
ctf = new ColorTransform( SPEED_FO, SPEED_FO, SPEED_FO, 1.0 );
temp = new Sprite();
addEventListener( Event.ENTER_FRAME, update, false, 10 );
}
private function update( e:Event ):void {
for ( var i:int = 0; i < 1; ++i ) {
fire();
}
canvas_bd.colorTransform( canvas_bd.rect, ctf );
}
private function fire():void {
var x:Number = stage.stageWidth / 2;
var y:Number = stage.stageHeight / 2;
var v:Number = 3*Math.random();
var r:Number = 2*Math.PI * Math.random();
var vx:Number = v * Math.cos( r );
var vy:Number = v * Math.sin( r );
var size:Number = 1 + 4*Math.random();
var color:uint = 0xffffff * Math.random();
var mtx:Matrix = new Matrix();
var bullet:TextField = new TextField();
bullet.textColor = color;
bullet.defaultTextFormat = tf;
bullet.autoSize = "left";
var len:int = Math.random() * 5;
bullet.text = text.substr(textIndex, len);
textIndex = (textIndex + len) % text.length;
bullet.selectable = false;
temp.addChild( bullet );
bullet.addEventListener( Event.ENTER_FRAME, function( e:Event ):void {
v += 0.1;
r += 0.03;
vx = v * Math.cos( r );
vy = v * Math.sin( r );
x += vx;
y += vy;
mtx.tx = x;
mtx.ty = y;
canvas_bd.draw( bullet, mtx );
if ( ( x < 0 ) || ( y < 0 ) || ( x > stage.stageWidth ) || ( y > stage.stageHeight ) ) {
bullet.removeEventListener( e.type, arguments.callee );
temp.removeChild( bullet );
bullet = null;
}
}, false, 1 );
}
}
}