ちょいちゃっと
以前作りたかったものをリベンジ的に・・・
今後はこれをサーバを駆使して複数人でできるようにしたいです。日本語だと思った動作がしないのが残念です
/**
* Copyright venthels ( http://wonderfl.net/user/venthels )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/h3Kg
*/
package {
import flash.display.Sprite;
import flash.text.*;
import flash.events.KeyboardEvent;
import flash.events.TextEvent;
import flash.events.Event;
import flash.utils.Timer;
import flash.events.TimerEvent;
public class main extends Sprite {
private var pu_sp:public_sprite = new public_sprite();
//private var pu_tf:public_textField;
private var my_tf:TextField = new TextField();
private var stAry:Array = new Array();
private var tiAry:Array = new Array();
private var tim:Timer;
private var count:int = 0;
public function main():void {
/*
pu_tf.x = 10;
pu_tf.y = 5;
pu_tf.width = stage.stageWidth-10;
pu_tf.height = stage.stageHeight-40;
stage.addChild(pu_tf);
*/
pu_sp.x = 10;
pu_sp.y = 5;
//pu_sp.width = stage.stageWidth-10;
//pu_sp.height = stage.stageHeight-40;
//pu_sp.graphics.lineStyle(2, 0x000000);
//pu_sp.graphics.drawRect(0, 0, stage.stageWidth-10, stage.stageHeight-40);
pu_sp.sizeCheng(stage.stageWidth-10, stage.stageHeight-40, 1);
stage.addChild(pu_sp);
my_tf.x = 10;
my_tf.y = stage.stageHeight-30;
my_tf.width = stage.stageWidth-10;
my_tf.height = 20;
my_tf.border = true;
my_tf.type = TextFieldType.INPUT;
my_tf.selectable = true;
my_tf.text = "文字を入力しENTER";
stage.addChild(my_tf);
//my_tf.addEventListener(Event.CHANGE, ct);
my_tf.addEventListener(TextEvent.TEXT_INPUT, ti);
my_tf.addEventListener(KeyboardEvent.KEY_DOWN, kd);
tim = new Timer(10);
tim.addEventListener(TimerEvent.TIMER, countFunc);
tim.start();
}
private function ti(e:TextEvent):void {
//trace(e.text);
stAry.push(e.text);
tiAry.push(count);
count = 0;
}
private function kd(e:KeyboardEvent):void {
if(e.keyCode == 13 && my_tf.text) {
pu_sp.addTf(stAry, tiAry);
//配列初期化
for(var i:int=0; i<stAry.length;) {
stAry.pop();
}
for(var j:int=0; j<tiAry.length;) {
tiAry.pop();
}
my_tf.text = "";
}
}
private function countFunc(e:TimerEvent):void {
count++;
}
}
}
import flash.display.Sprite;
import flash.text.*;
class public_sprite extends Sprite {
public var my_sp:Sprite = new Sprite();
private var pu_tfAry:Array = new Array();
public function public_sprite():void {
this.graphics.lineStyle(2, 0x000000);
this.graphics.drawRect(0, 0, 1, 1);
}
public function sizeCheng(_w:Number, _h:Number, _lw:Number):void {
this.graphics.clear();
this.graphics.lineStyle(_lw, 0x000000);
this.graphics.drawRect(0, 0, _w, _h);
}
public function addTf(_string:Array, _time:Array):void {
//共有テキストフィールドの追加
var ind:int = pu_tfAry.push(new public_textField(_string, _time, Math.random()*255*255*255));
//共有テキストフィールドの移動、スライド
for(var i:int=0; i<pu_tfAry.length-1; i++) {
pu_tfAry[i].moving(pu_tfAry[pu_tfAry.length-1].height);
}
this.addChild(pu_tfAry[ind-1]);
}
}
class public_textField extends TextField {
private var my_stAry:Array = new Array();
private var my_tiAry:Array = new Array();
private var my_fo:TextFormat = new TextFormat();
public function public_textField(_string:Array, _time:Array, _col:uint):void {
my_stAry = _string;
my_tiAry = _time;
this.autoSize = TextFieldAutoSize.LEFT;
this.background = true;
//this.backgroundColor = _col;
this.textColor = _col;
this.type = TextFieldType.DYNAMIC;
this.border = true;
writeFunc();
}
public function writeFunc():void {
for(var i:int=0; i<my_stAry.length; i++) {
this.appendText(my_stAry[i]);
if(!i == 0) {
//trace(my_tiAry[i]);
my_fo.size = (my_tiAry[i] / 3) + 5;
this.setTextFormat(my_fo, i-1, i);
}
}
//this.appendText("\n");
}
public function moving(_m:Number):void {
this.y += _m;
}
}