テキストと球
/**
* Copyright martial ( http://wonderfl.net/user/martial )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/wFrV
*/
package {
import flash.display.Sprite;
import flash.display.Shape;
import flash.geom.Matrix;
import flash.display.GradientType;
import flash.display.StageQuality;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.filters.GlowFilter;
import flash.events.*;
[SWF(backgroundColor=0x000000, width=465, height=465, frameRate=30)]
public class FlashTest extends Sprite {
private var matrix:Matrix;
private var shape:Shape;
private const STAGE_SIZE:uint = 465;
private var startColor:uint = 0xff0000;
private var endColor:uint = 0x000000;
private var tf:TextField;
private var tfm:TextFormat;
private var glow:GlowFilter;
private var dx:int=1, dy:int=1;
private var dAlpha:Number=0.03;
private var circle:Sprite;
private var dcx:int=5,dcy:int=5;
private var dcAlpha:Number=0.03;
public function FlashTest() {
// write as3 code here..
stage.quality = StageQuality.BEST;
matrix = new Matrix();
matrix.createGradientBox(STAGE_SIZE*1.5, STAGE_SIZE*1.5, 0, -100, -100);
// Background
shape = new Shape();
shape.graphics.beginGradientFill(
GradientType.RADIAL,
[startColor, endColor],
[1, 1],
[0, 230],
matrix
);
shape.graphics.drawRect(0, 0, STAGE_SIZE, STAGE_SIZE);
shape.graphics.endFill();
// Stripe
var stripe:Shape = new Shape();
var interval:Number = 30;
var i:uint;
while( stripe.height < STAGE_SIZE ) {
with ( stripe.graphics ) {
lineStyle( 15, 0xFFFFFF );
moveTo( 0, interval*i );
lineTo( STAGE_SIZE, interval*i );
}
i++;
}
addChild( stripe );
// Circle
circle = new Sprite();
circle.graphics.beginFill(0xff000000, 1);
circle.graphics.drawCircle(50, 50, 50);
circle.alpha = 0.5;
circle.x = 50;
circle.y = 200;
addChild(circle);
// TextField
tfm = new TextFormat();
tfm.color = 0xffffff;
tfm.size = 80;
tfm.font = "_sans";
tf = new TextField();
tf.defaultTextFormat = tfm;
tf.autoSize = TextFieldAutoSize.CENTER;
glow = new GlowFilter();
glow.color = 0xffffff;
glow.alpha = 0.3;
glow.blurX = 100;
glow.blurY = 100;
glow.strength = 30;
glow.quality = 3;
tf.filters = [glow];
tf.x = STAGE_SIZE / 2 - tf.textWidth;
tf.y = STAGE_SIZE / 2 - Number( tfm.size );
addChild( tf );
tf.text = "My First \n wonderfl";
addEventListener(Event.ENTER_FRAME, draw);
}
public function draw(event:Event):void {
// Text
tf.x += dx;
tf.y += dy;
glow.alpha += dAlpha;
tf.filters = [glow];
if(tf.x < 0 || (tf.x + tf.textWidth) > STAGE_SIZE){
dx *= -1;
}
if(tf.y < 0 || (tf.y + tf.textHeight) > STAGE_SIZE){
dy *= -1;
}
if(glow.alpha >= 1.0){
dAlpha *= -1;
}
if(glow.alpha <= 0){
dAlpha *= -1;
}
// Circle
circle.x += dcx;
circle.y += dcy;
circle.graphics.clear();
circle.graphics.beginFill(0xff000000, 1);
circle.graphics.drawCircle(50, 50, 50);
circle.alpha += dcAlpha;
addChild(circle)
if(circle.x < 0 || (circle.x + circle.width) > STAGE_SIZE){
dcx *= -1;
}
if(circle.y < 0 || (circle.y + circle.height) > STAGE_SIZE){
dcy *= -1;
}
if(circle.alpha >= 1.0){
dcAlpha *= -1;
dcx +=2;
dcy -=2;
}
if(circle.alpha <= 0){
dcAlpha *= -1;
dcx -=2;
dcy +=2;
}
}
}
}