速查手册
API
基本操作
- clear():void
- clone(object:*):*
(Utils.clone) 有些(TODO)类型无法正确复制 - foreach(object:Object, iterator:Function):void
(Utils.foreach) 只能访问公开可遍历属性。例foreach({1:2, 3:4}, function(key, value) {trace(key, value);});
- load(library:String, onload:Function):void
(libBitmap
已内嵌)。只在加载成功时调用onload。例load('libBitmap', function(){trace('ok', Bitmap);});
- trace(… args):void
例trace(1, 2, [3,4], '5 6', trace);
- $G._get(name:String):*
($G._, Global._get, Global._) - $G._set(name:String, value:*):void
(Global._set) - ScriptManager.clearEl():void
停止并清除$.createComment()、$.createShape()、$.createCanvas()、$.createButton()、Bitmap.createBitmap()产生的运动元件。 - ScriptManager.clearTimer():void
清除只由interval()产生的计时器。不清除timer()。 - ScriptManager.clearTrigger():void
清除只由Player.keyTrigger()产生的键盘事件侦听。不清除Player.commentTrigger()。
时间
- clearTimeout(timeout_id:uint)
中止由timeout_id指定的延时操作。 - getTimer():int
毫秒 - interval(exec:Function, delay_msec:Number = 1000, repeatCount:uint = 1):Timer
(Utils.interval) 重复定时执行。repeatCount为0则无限重复。delay推荐最小20毫秒(再小影响性能)。 - timer(exec:Function, delay_msec:Number = 1000):uint
(Utils.delay) 一次延时执行。delay最小1毫秒。返回timeout_id。
数据转换
- parseInt(str:String, radix:uint = 0):Number
- parseFloat(str:String):Number
- $.toIntVector(ints:Array):Vector.<int>
- $.toUintVector(uints:Array):Vector.<uint>
- $.toNumberVector(numbers:Array):Vector.<Number>
- String.fromCharCode(… charCodes):String
Unicode码,0到65535。例trace(String.fromCharCode(27979, 35797, 10, 9731, 9773));
- Utils.distance(x1:Number, y1:Number, x2:Number, y2:Number):Number
即Math.sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2))
- Utils.formatTimes(second:Number):String
时间格式mm:ss;例trace(Utils.formatTimes(Player.time / 1000));
- Utils.hue(value:int):int
最小0 最大359 - Utils.rand(min:Number, max:Number):Number
整数,即Math.floor(min + Math.random() * (max - min))
- Utils.rgb(r:int, g:int, b:int):int
耗时是r << 16 | g << 8 | b
的2倍。
几何
详细参数见链接的Adobe手册页面。
- $.createColorTransform(…):ColorTransform
- $.createGradientBox(…):Matrix
即(new Matrix()).createGradientBox(...)
。用于beginGradientFill()和lineGradientStyle()。 - $.createMatrix(…):Matrix
- $.createMatrix3D(…):Matrix3D
- PerspectiveProjection
clone($.root.transform.perspectiveProjection)
- $.createPoint(x:Number = 0, y:Number = 0):Point
- Rectangle
$.root.getRect(null)
或Bitmap.createRectangle(x, y, w, h)
- $.createVector3D(…):Vector3D
- $.pointTowards(…):Matrix3D
- $.projectVector(…):Vector3D
- $.projectVectors(…):void
库
Player信息
- Player.videoWidth:uint, Player.videoHeight:uint [只读]
视频等比例尺寸 - $.width:uint, $.height:uint [只读]
(Player.width:uint, Player.height:uint) 播放窗口尺寸;包括黑边 - $.stageWidth:uint, $.stageHeight:uint [只读]
Flash界面尺寸 - $.screenWidth:uint, $.screenHeight:uint [只读]
($.fullScreenWidth:uint, $.fullScreenHeight:uint) 屏幕尺寸 - Player.commentList:Array [只读]
一组CommentData。 - Player.state:String [只读]
stop
,pause
,playing
- Player.time:Number [只读]
毫秒
Player控制
- Player.commentTrigger(onComment:Function, timeout_msec:Number = 1000):uint
返回timeout_id。不能用clearTimeout或者ScriptManager清除。 例Player.commentTrigger(function(c){trace(c, c.text);}, 1 << 30);
- Player.createSound(sample:String, onload:Function = null):ScriptSound
目前已知sample:btnover
。ScriptSound.play(startTime:Number = 0, loops:int = 0):void. 查看样例 - Player.jump(av:String, page:int = 1, newwindow:Boolean = false):void
- Player.keyTrigger(onKey:Function, timeout_msec:Number = 1000, up:Boolean = false):uint
timeout最大2147483647,小于0不工作。返回timeout_id。查看样例。 - Player.pause():void
- Player.play():void
- Player.refreshRate:int
不工作;暂不修复。 - $.frameRate:Number
大于0小于120,超过60一般无意义。 - Player.seek(time_msec:Number):void
只能seek到关键帧。 - Player.setMask(mask:DisplayObject):void
即player.parent.mask = mask;
图形元件
以下通用参数(附默认值):{x:0, y:0, z:null, scale:1, alpha:1,
parent:$.root, lifeTime:3, motion:{}}
- $.createButton(params:Object):CommentButton
{text:"Button", width:60, height:30, onclick:undefined}
- $.createCanvas(params:Object):CommentCanvas
- $.createComment(text:String, params:Object):CommentField
{color:0xffffff, font:"黑体", fontsize:25}
- $.createShape(params:Object):CommentShape
- $.createTextField():CommentField
不初始化 - $.createTextFormat(…):TextFormat
Bitmap库
- Bitmap.createBitmap(params:Object):CommentBitmap
{bitmapData:undefined, pixelSnapping:"auto", smothing:undefined, scale:1}
- Bitmap.createBitmapData(width:int, height:int, transparent:Boolean = true, fillColor:uint = 0xFFFFFFFF):BitmapData
- Bitmap.createParticle(params:Object):CommentBitmap
TODO - Bitmap.createRectangle(x:Number, y:Number, width:Number, height:Number):Rectangle
滤镜
无法获得ShaderFilter。详细参数见Adobe手册页面。
- $.createBevelFilter(…):BevelFilter
- $.createBlurFilter(…):BlurFilter
- $.createColorMatrixFilter(…):ColorMatrixFilter
- $.createConvolutionFilter(…):ConvolutionFilter
- $.createDisplacementMapFilter(…):DisplacementMapFilter
- $.createDropShadowFilter(…):DropShadowFilter
- $.createGlowFilter(…):GlowFilter
- $.createGradientBevelFilter(…):GradientBevelFilter
- $.createGradientGlowFilter(…):GradientGlowFilter
内部
- $.root
- ScriptManager.pushEl(param1:IMotionElement):void
- ScriptManager.popEl(param1:IMotionElement):void
- ScriptManager.pushTimer(param1:Timer):void
- ScriptManager.popTimer(param1:Timer):void
类定义
CommentData
- blocked:Boolean
- blockType:uint
- border:Boolean
- color:uint
- credit:Boolean
- danmuId:uint [只读]
- date:String
- deleted:Boolean
- id:uint
- mode:uint
- msg:String
- live:Boolean
- locked:Boolean
- on:Boolean
- pool:int
- preview:Boolean
- reported:Boolean
- size:int
- stime:Number [只读] 秒
- text:String [只读]
- type:String
- userId:String [只读]
例Player.commentList.forEach(function(e) {trace(e.stime, e.text);});
MotionManager
- running:Boolean [只读]
- reset():void
- play():void
- stop():void
- forcasting(param1:Number):Boolean
- setPlayTime(param1:Number):void
- initTween(param1:Object, param2:Boolean = false):String
- initTweenGroup(motionGroup:Array, lifeTime:Number = NaN):void
- setCompleteListener(param1:Function):void
Comment元件通用
- motionManager:MotionManager [只读]
- initStyle(params:Object):void
CommentBitmap除外 - remove():void
CommentBitmap → Bitmap
- motionManager:MotionManager [读写]
- setParent(parent:*):void
即parent.addChild(this)
CommentButton → Sprite
- text:String
- fillColors:Array
- fillAlphas:Array
CommentCanvas → Sprite
CommentField → TextField
CommentShape → Shape
样板代码
Player.keyTrigger
Keysym = {65: 'A', 68: 'D', 83: 'S', 87: 'W'};
var keyPressed = {};
ScriptManager.clearTrigger();
clearTimeout(Player.keyTrigger(function(keyCode) {
keyPressed[Keysym[keyCode]] = true;
}));
clearTimeout(Player.keyTrigger(function(keyCode) {
keyPressed[Keysym[keyCode]] = false;
}, 1000, true));
ScriptManager.clearTimer();
interval(function() {
trace('Key A is', keyPressed.A ? 'pressed.' : 'not pressed.');
}, 100, 100);
//Press A and observe debug console
Player.createSound
var btn = $.createButton({
text:"mouseOver",x:$.width * 0.5 - 60,y:$.height * 0.5 - 15,lifeTime:0,width:120,
onclick:function()
{
trace("btnover");
}
});
btn.addEventListener("mouseOver",function()
{
var sound =
Player.createSound("btnover",function()
{
trace(sound.loadPercent(),sound.remove,sound.stop);
});
sound.play();
t=interval(function(){btn.text=t.delay-=10;sound.play();},1000,1000);
});
鼠标定位
trace($.root.mouseX, $.root.mouseY);
或者:
var c = $.createComment('+', {lifeTime:0});
c.transform.matrix3D = null;
c.bold = false;
var canvas = $.root;
canvas.graphics.beginFill(0, 0);
canvas.graphics.drawRect(0, 0, $.width, $.height);
canvas.graphics.endFill();
canvas.mouseEnabled = true;
canvas.addEventListener('mouseMove', function (e) {
c.x = e.localX - c.width / 2;
c.y = e.localY - c.height / 2;
});
Bitmap库加载
(Bitmap库已内嵌无需再加载,以下仅作示例。)
function startApplication() {
var bmd = Bitmap.createBitmapData(40, 30, false, 0xffffff);
var bmp = Bitmap.createBitmap({bitmapData:bmd, lifeTime:0, scale:2});
}
var loadText = $.createComment('加载Bitmap库,稍候…', {lifeTime:0, fontsize:14});
loadText.transform.matrix3D = null;
var loadTimeout = timer(function() {
loadText.text = '载入超时,请刷新重试或检查网络连接。';
}, 5000);
load('libBitmap', function() {
clearTimeout(loadTimeout);
loadText.remove();
startApplication();
});
遍历显示列表
function getChildren(path, node) {
trace('[' + path + ']', node);
if (!node.hasOwnProperty('numChildren')) return;
for (var i = 0; i < node.numChildren; i++)
getChildren(path.concat(i), node.getChildAt(i));
}
getChildren([], $.root);
function getChildFrom(root, path) {
if (!path.length) return root;
return getChildFrom(root.getChildAt(path.shift()), path);
}
检测seek
var probe = $.createShape({lifeTime:0});
probe.motionManager.setPlayTime(365 * 24 * 3600 * 1000);
$.root.addEventListener('enterFrame', function() {
if (!probe.visible) {
probe.visible = true;
trace('seeking to', Utils.formatTimes(Player.time / 1000));
}
});
已知问题
(TODO: 扩充重现方法和结果)
- 安全考虑,TextField.htmlText被去掉所有html。
- 安全考虑,.loaderInfo属性被禁止访问。
- UI控制考虑,.root、.parent、.stage属性被禁止访问。
- Bitmap.createBitmap的smoothing参数被错别字成smothing。
- $.createComment、$.createShape、$.createCanvas、$.createButton会给进行DisplayObject.z = null导致产生一个Matrix3D导致图形模糊。解决方法
displayObject.transform.matrix3D = null;
。 - flash.display::Graphics里面没有cubicCurveTo方法,这是在FP11.0的特性(2011年10月)。
无法修复。站方player.swf开发环境Flex SDK 4.1尚未支持加入此特性。近期无升级计划。 - 字符串中的
/n
会在提交后被转义成换行。 []
访问符语法问题,无法嵌套a = [0,1]; b = [0,1]; trace(a[0], b[a[0]]);
- 调用类静态方法。
String.fromCharCode()
可以这样实现:''.constructor.fromCharCode()
。