Flash开发,Flash语言(AS2/3)和Flash IDE的隐藏功能/技巧

Art*_*kii 17 ide flash actionscript actionscript-3

大家好,我很惊讶,隐藏功能系列中还没有Flash 隐藏功能的帖子,我已经跟踪了一段时间了.

有一个最近的AS3/Flex,但它并不是非常活跃,当我在这里说Flash时,我并不完全是指AS3.

隐藏功能系列非常适合对某种语言不熟悉的人.它在一个地方展示了绳索和某些有价值的技巧.我认为这是个好主意.甚至专家有时也会发现他们从未听说过的伎俩.

当我开始使用Flash时,与其他编程语言相比,我对Flash IDE以及Flash的奇怪概念感到吃惊.

那么,这里有:Flash作为一种语言(AS2/3)Flash IDE的一些隐藏功能是什么?

让乐趣开始.

enz*_*uri 11

[AS3]使用数组或向量的提示

通过阵列的最快方式,始终从后面

var i:int = array.length;
var item:Object;
while(i--)
{
   item = array[i];
}
Run Code Online (Sandbox Code Playgroud)

清除阵列,

//faster than array = []
array.length = 0;

//garbage friendly
while(array.length)
{
    array.pop();
}
Run Code Online (Sandbox Code Playgroud)

推动和拼接

//faster than array.push();
array[array.length] = "pushed value";

//faster than splice(index, 1)
var index:int = array.indexOf(splicee);
array[index] = null;
array.splice(array.length, 1);
Run Code Online (Sandbox Code Playgroud)

克隆

//fastest way to clone
var newArray:Array = array.concat();

//fastest manipulation
var mapFunction:Function = function(item:Object, index:int, source:Array):Object
{
    return //your cloning or morphing here
}
var newArray:Array = array.map(mapFunction);
Run Code Online (Sandbox Code Playgroud)


小智 8

MovieClip.addFrameScript()是一种未记录的ActionScript 3.0功能,允许您指定当Movieclip时间轴的播放头输入特定帧编号时调用的函数.

function someFunction():void {

}

movieclip_mc.addFrameScript(4,someFunction);
Run Code Online (Sandbox Code Playgroud)

帧号基于零(第一帧= 0)并且只需要是整数,但是如果你想使用帧标签,你可以使用这样的东西:

function addFrameLabelScript(frame:String, func:Function):void{
    var labels:Array = currentLabels;
    for(var i:int=0;i<labels.length;i++){
        if(labels[i].name == frame){
            addFrameScript(labels[i].frame-1,func);
        }
    }
} 
Run Code Online (Sandbox Code Playgroud)


Ric*_*lay 7

[Flash IDE]

这不是一个特征,因为它是一个陷阱.为FLA指定文档类时,编译器不会对该类进行子类化,而是对其进行修改.

当您有多个具有相同文档类的SWF时,这会导致问题,所有SWF都被加载到另一个SWF中(因为两个具有相同名称的类不能并排加载到同一个应用程序域中).它导致第一个被加载,第二个使用第一个被修改的类,产生奇怪的错误(你可以想象).

解决方案是:

  • 为每个FLA创建一个代理类,该类是文档类的子类
  • 将每个SWF加载到新的子应用程序域中

  • 哦..我看到这是正确的答案!8P (2认同)

小智 5

Graphics::drawRoundRectComplex (x:Number, y:Number, width:Number, height:Number, topLeftRadius:Number, topRightRadius:Number, bottomLeftRadius:Number, bottomRightRadius:Number) : void;
Run Code Online (Sandbox Code Playgroud)

它没有在任何地方记录,但论坛帖子解释更多.