forked from: MGによく使われるアレ
クリックで伸びます
// forked from break's MGによく使われるアレ
package {
import flash.display.Sprite;
import flash.events.*;
//クリックで伸びます
[SWF(backgroundColor = "#000000", frameRate = 120)]
public class Main extends Sprite {
public function Main() {
this.addEventListener(Event.ADDED, init);
}
private static var ee:Effect;
private function init(e:Event = null):void {
stage.removeEventListener(Event.ADDED, init);
stage.addEventListener(MouseEvent.CLICK, draw);
ee = new Effect(stage);
}
private function draw(e:MouseEvent = null):void {
if (Math.random() * 2 < 1) {
var type:String = (Math.random() * 2 < 1)?"LEFT":"RIGHT";
ee.startTextOut("醉解心语", type, 0xffffff * Math.random(), 0x0, 2, 7, 0xfff, 5, 200);
}else{
var s:Sprite = new Sprite();
var q:Number = Math.random();
for (var k:uint = 0; k < 5; k++){
s.graphics.lineStyle(10, 0xffffff * q *k);
s.graphics.drawCircle(0, 232, 20*k);
}
ee.startSpriteOut(s, "LEFT", 0x0, 1, 1, 0xfff, 232, 0);
}
}
}
}
import flash.display.*;
import flash.events.*;
import flash.geom.*;
import flash.text.*;
class Effect {
private var stage:Stage;
public function Effect(_stage:Stage) {stage = _stage;}
public function startTextOut(string:String, type:String, textColor:uint, background:uint, speed:Number, scale:uint, vw:uint, vx:uint, vy:uint):void{
var textField:TextField = new TextField();
textField.text = string as String;
textField.textColor = textColor;
textField.autoSize = TextFieldAutoSize.LEFT;
var bitmapData:BitmapData = new BitmapData(textField.width * scale + vx + vw, textField.height * scale, false, 0x0);
var bitmap:Bitmap = stage.addChild(new Bitmap(bitmapData, PixelSnapping.AUTO, false)) as Bitmap;
bitmap.y = vy;
bitmapData.draw(textField, new Matrix(scale, 0, 0, scale, vx, 0));
stage.addEventListener(Event.ENTER_FRAME, update);
var counter:uint;
function update(e:Event = null):void {
if (counter > textField.width * scale + vx) {
stage.removeEventListener(Event.ENTER_FRAME, update);
stage.removeChild(bitmap);
}
if(type == "LEFT") bitmapData.fillRect(new Rectangle(textField.width * scale - counter + vx +1, textField.y, (textField.width + vx) * scale + 465, textField.height * scale), 0x0);
else if(type == "RIGHT") bitmapData.fillRect(new Rectangle(vx+counter - vw, textField.y, vw, textField.height * scale), 0x0);
for (var k:uint = 0; k < textField.height * scale; k++) {
if (type == "LEFT") { if (bitmapData.getPixel(textField.width * scale - counter + vx, k)) bitmapData.fillRect(new Rectangle(textField.width * scale - counter + vx, k, vw * 2 + vy, 1), bitmapData.getPixel(textField.width * scale- counter + vx, k)); }
else if(type == "RIGHT"){if (bitmapData.getPixel(vx + counter, k)) bitmapData.fillRect(new Rectangle(vx + counter - vw, k, vw, 1), bitmapData.getPixel(vx + counter, k));}
}
counter += speed;
}
}
public function startSpriteOut(sprite:Sprite, type:String, background:uint, speed:uint, scale:uint, vw:uint, vx:uint, vy:uint):void{
var bitmapData:BitmapData = new BitmapData(sprite.width * scale + vx + vw, sprite.height * scale * 2, false, 0x0);
var bitmap:Bitmap = stage.addChild(new Bitmap(bitmapData, PixelSnapping.AUTO, false)) as Bitmap;
bitmap.y = vy;
bitmapData.draw(sprite, new Matrix(scale, 0, 0, scale, vx, 0));
stage.addEventListener(Event.ENTER_FRAME, update);
var counter:uint;
function update(e:Event = null):void {
if (counter > sprite.width * scale * 2 + vx) {
stage.removeEventListener(Event.ENTER_FRAME, update);
stage.removeChild(bitmap);
}
if(type == "LEFT") bitmapData.fillRect(new Rectangle(sprite.width * scale - counter + vx +1, sprite.y, (sprite.width + vx) * scale + 465, sprite.height * scale * 2), 0x0);
else if(type == "RIGHT") bitmapData.fillRect(new Rectangle(vx+counter - vw, sprite.y, vw, sprite.height * scale * 2), 0x0);
for (var k:uint = 0; k < sprite.height * scale * 2; k++) {
if (type == "LEFT") { if (bitmapData.getPixel(sprite.width * scale - counter + vx, k)) bitmapData.fillRect(new Rectangle(sprite.width * scale - counter + vx, k, vw * 2 + vy, 1), bitmapData.getPixel(sprite.width * scale- counter + vx, k)); }
else if(type == "RIGHT"){if (bitmapData.getPixel(vx + counter, k)) bitmapData.fillRect(new Rectangle(vx + counter - vw, k, vw, 1), bitmapData.getPixel(vx + counter, k));}
}
counter += speed;
}
}
}