1、项目属性编译参数中可以定义swf的大小背景色及每秒帧数:
-default-size 800 600 -default-frame-rate 31
=============================================================
2、取随机数:
Math.random()
==============================================================
3、安装debug版本flashplayer后,跟着debug信息,可以设置将debug信息输出到某个文件中
C:\Documents and Settings\[user name]\mm.cfg 设置此mm.cfg
mm.cfg 文件允许你设置如下变量:
TraceOutputFileEnable 设置值为0 (不写入文件) 或1 (写入文件).
TraceOutputFileName 文件路径,如果没有指定,会在mm.cfg的同目录下生成一个叫flashlog.txt文件 ErrorReportingEnable 设置值为0 (不输出错误信息到文件) 或1 (输出错误信息). 默认为0
MaxWarnings 写入文件的错误信息数量。如果为0则没有限制。
例:
TraceOutPutFileName=C:/Documents and Settings/yinsw/Application Data/Macromedia/Flash Player/Logs/flashlog.txt
ErrorReportingEnable=1
TraceOutputFileEnable=1
MaxWarnings=100
==============================================================
4、监听键盘事件
接受这些事件的对象必须出于激活状态。我们需要在主程序中加入(stage.focus = this;)。
例:
stage.focus = this;
addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
private function onKeyDown(event:KeyboardEvent):void {
trace("key down: " + event.charCode);
}
==============================================================
5、监听每帧
addEventListener(Event.ENTER_FRAME, EnterFrameHandler);
==============================================================
6、变化角度
rotation
例:_sprite每帧角度加5:
private function EnterFrameHandler(event:Event) {
_sprite.rotation += 5;
}
==============================================================
7、检测是否是数字
isNaN(变量) true 不是数字
==============================================================
8、类型比较
基本类型(string, number, boolean) 复合类型(object, sprite, array)
基本类比较的是“值”,复合类型比较得是引用
==============================================================
9、for循环的条件语句还可以设置多个初始值和进步值
例:
for (var i:int = 0, j:int = 10; i < 10; i++, j--) {
trace("i is " + i);
trace("j is " + j);
}
==============================================================
10、Timer类
Timer 类是ActionScript 3.0新增的, 来代替早期的setInterval( ) 和setTimeout( ) 函数。
var timer:Timer = new Timer(delay, repeatCount);
例:事件每隔5毫秒激活一次
public class ExampleApplication extends Sprite { private var _PreviousTime:Number = 0; public function ExampleApplication( ) { var tTimer:Timer = new Timer(500, 10); tTimer.addEventListener(TimerEvent.TIMER, onTimer); tTimer.start( ); } private function onTimer(event:TimerEvent):void { trace(flash.utils.getTimer( ) - _PreviousTime); _PreviousTime = flash.utils.getTimer( ); } }
如果你想模拟setInterval( ) 函数,把重复次数设为0。
stop( ) 方法类似于clearInterval( ) 函数,停止定时器.
如果想模拟setTimeout( )函数,设置重复数为1,定时器等到指定时间激活一次事件,然后停止。
Timer类最好的用处就是创建动画而不依赖于影片帧速。看下面的例子,两个定时器时间间隔分
别为50微妙和100微妙:
package { import flash.display.Sprite; import flash.events.TimerEvent; import flash.utils.Timer; public class ExampleApplication extends Sprite { private var _square:Sprite; private var _circle:Sprite; public function ExampleApplication( ) { // 创建两个图形 _square = new Sprite( ); _square.graphics.beginFill(0xff0000); _square.graphics.drawRect(0, 0, 100, 100); _square.graphics.endFill( ); addChild(_square); _square.x = 100; _square.y = 50; _circle = new Sprite( ); _circle.graphics.beginFill(0x0000ff); _circle.graphics.drawCircle(50, 50, 50); _circle.graphics.endFill( ); addChild(_circle); _circle.x = 100; _circle.y = 200; // 创建两个定时器,启动 var squareTimer:Timer = new Timer(50, 0); squareTimer.addEventListener(TimerEvent.TIMER, onSquareTimer); squareTimer.start( ); var circleTimer:Timer = new Timer(100, 0); circleTimer.addEventListener(TimerEvent.TIMER, onCircleTimer); circleTimer.start( ); } // 定义两个事件句柄 private function onSquareTimer(event:TimerEvent):void { _square.x++; } private function onCircleTimer(event:TimerEvent):void { _circle.x++; } } }
当然用enterFrame 事件也可以实现的,但Timer 技术更加灵活。
==============================================================
11、函数参数,可以通过 arguments 获得
==============================================================
12、抛出异常
可以在某个函数或方法中抛出异常,在调用该函数的方法中使用try/catch截获异常
==============================================================