case [8] 9818 (その2)
case [8] 9818 (その2)
♥0 |
Line 114 |
Modified 2011-01-06 17:16:31 |
MIT License
archived:2017-03-30 01:27:55
ActionScript3 source code
/**
* Copyright ProjectNya ( http://wonderfl.net/user/ProjectNya )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/kUe3
*/
////////////////////////////////////////////////////////////////////////////////
// case [8] 9818 (その2)
////////////////////////////////////////////////////////////////////////////////
package {
import flash.display.Sprite;
import flash.net.URLLoader;
import flash.net.URLLoaderDataFormat;
import flash.net.URLRequest;
import flash.events.Event;
import flash.utils.Timer;
import flash.events.TimerEvent;
[SWF(backgroundColor="#FFFFFF", width="465", height="465", frameRate="30")]
public class Main extends Sprite {
private var label:Label;
private var txtlist:Array;
private var txtId:uint = 0;
private var loader:URLLoader;
private var timer:Timer;
private static var interval:uint = 2000;
private static var basePath:String = "http://www.project-nya.jp/";
private static var filePath:String = "test/t898182.txt";
private static var CR:String = String.fromCharCode(13);
private static var LF:String = String.fromCharCode(10);
public function Main() {
//Wonderfl.capture_delay(1);
init();
}
private function init():void {
label = new Label(200, 200);
addChild(label);
label.x = 10;
label.y = 10;
label.textColor = 0x000000;
label.text = "";
//
loader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.TEXT;
loader.addEventListener(Event.COMPLETE, complete, false, 0, true);
loader.load(new URLRequest(basePath + filePath));
}
private function complete(evt:Event):void {
parse(evt.target.data);
}
private function parse(src:String):void {
var str:String = unifyLineFeedCode(src);
var list:Array = str.split(LF+LF);
if (list[list.length - 1] == "EOF") list.pop();
txtlist = new Array();
for (var n:uint = 0; n < list.length; n++) {
var element:String = list[n];
var elements:Array = element.split(LF);
txtlist.push(elements[2]);
}
start();
}
private function unifyLineFeedCode(str:String):String {
str = str.split(CR+LF).join(LF);
str = str.split(CR).join(LF);
return str;
}
private function start():void {
show(txtId);
timer = new Timer(interval);
timer.addEventListener(TimerEvent.TIMER, transit, false, 0, true);
timer.start();
}
private function transit(evt:TimerEvent):void {
txtId = (txtId + 1)%txtlist.length;
show(txtId);
}
private function show(id:uint):void {
label.text = txtlist[id];
}
}
}
//////////////////////////////////////////////////
// Labelクラス
//////////////////////////////////////////////////
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFieldType;
import flash.text.TextFieldAutoSize;
import flash.text.AntiAliasType;
import flash.text.TextFormat;
import flash.text.TextFormatAlign;
class Label extends Sprite {
private var txt:TextField;
private static var fontType:String = "_ゴシック";
private var _width:uint = 20;
private var _height:uint = 20;
private var size:uint = 12;
public static const LEFT:String = TextFormatAlign.LEFT;
public static const CENTER:String = TextFormatAlign.CENTER;
public static const RIGHT:String = TextFormatAlign.RIGHT;
public function Label(w:uint, h:uint, s:uint = 12, align:String = LEFT) {
_width = w;
_height = h;
size = s;
draw(align);
}
private function draw(align:String):void {
txt = new TextField();
addChild(txt);
txt.width = _width;
txt.height = _height;
txt.autoSize = align;
txt.type = TextFieldType.DYNAMIC;
txt.selectable = false;
//txt.embedFonts = true;
//txt.antiAliasType = AntiAliasType.ADVANCED;
var tf:TextFormat = new TextFormat();
tf.font = fontType;
tf.size = size;
tf.align = align;
txt.defaultTextFormat = tf;
textColor = 0x000000;
}
public function set text(param:String):void {
txt.text = param;
}
public function set textColor(param:uint):void {
txt.textColor = param;
}
}