2013/2/5 久米
asファイルはクラスを記述するファイルである。インスタンス化するにはnewを使用する。
すべてのクラス(adobe)にはいろいろなasファイルの例が載ってる。それを使用する方法は、
なお、packageとはasファイルが入るフォルダ構成のことである。
演習1
すべてのクラス(adobe)のTimerクラスを開きその一番下にあるスクリプトを試してみよ。
| Timerクラスに載っているASファイルの例 |
package {
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.display.Sprite;
public class TimerExample extends Sprite {
public function TimerExample() {
var myTimer:Timer = new Timer(1000, 2);
myTimer.addEventListener("timer", timerHandler);
myTimer.start();
}
public function timerHandler(event:TimerEvent):void {
trace("timerHandler: " + event);
}
}
}
|
演習2 Graphicsクラスを開きその一番下にあるスクリプトを試してみよ。
演習3 ドラックドロップできる丸をasファイルで作成し、ドラックしてみよ。
ヒント:丸の記述
this.graphics.beginFill(0xFFCC00);//色
this.graphics.drawCircle(円の中心のx座標,円の中心のy座標,半径);
this.graphics.endFill();
演習4 回る四角をasファイルで作成し、動かしてみよ。
ヒント:四角の記述
this.graphics.beginFill(0xFFCC00);//色
this.graphics.drawRoundRect(左肩のx座標,左肩のy座,幅,高さ,丸み角度);
this.graphics.endFill();
シンボルの親クラスに自作asクラスを指定する場合は、
シンボルプロパティの基本クラスに自作したasクラス名を記述する。