Technology
TextFieldとTimer
2010-08-28ActionScript
テキストフィールドをひとつ配置し、タイマーで値を変えてみます。
public class Mainからpublic function Mainの間にあるtextFieldとかintervalが、Mainクラスのメンバ変数っぽいものです。Main関数内でTextFieldを実体化させています。
package{
import flash.display.*;
import flash.text.*;
import flash.utils.Timer;
import flash.events.TimerEvent;
public class Main extends Sprite{
private var textField:TextField;
private var interval:uint=1000; // millisecond
private var repeat:uint = 5;
private var myTimer:Timer = new Timer(interval,repeat);
public function Main() {
textField = new TextField();
textField.x = 0;
textField.y = 50;
textField.text = "Hello, world!!";
addChild(textField);
myTimer.start();
myTimer.addEventListener(TimerEvent.TIMER, timerHandler);
myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, completeHandler);
}
private function timerHandler(e:TimerEvent):void{
textField.appendText("n");
textField.appendText("Hello!");
}
private function completeHandler(e:TimerEvent):void{
textField.text = "owata";
}
}
}
Topic
- Languages (24)
- ActionScript (8)
- C# (1)
- Java (6)
- Android (2)
- JavaScript (5)
- JavaScript (4)
- node.js (1)
- Perl (4)
- Database (3)
- MySQL (3)
- Miscellaneous (5)