我們來看一下簡單的例子~
假設我們放一個MovieClip在Stage上,並在此MovieClip下點程式,讓它能夠隨著播放時進行旋轉~
以下均發佈成Flash Player 8 & ActionScript 2.0的swf file
程式一
onClipEvent (enterFrame)
{
this._rotation += 5;
}
程式一ActionCode
onClipEvent (enterFrame)
{
ActionConstantPool "this" "_rotation"
ActionPush "this"
ActionGetVariable
ActionPush "_rotation" "this"
ActionGetVariable
ActionPush "_rotation"
ActionGetMember
ActionPush 5
ActionAdd2
ActionSetMember
ActionEndFlag
}
程式一的ActionCode是最多的一個,我們再試著將「this」移掉試試:
程式二
onClipEvent (enterFrame)
{
_rotation += 5;
}
程式二ActionCode
onClipEvent (enterFrame)
{
ActionConstantPool ""
ActionPush "" 10 "" 10
ActionGetProperty
ActionPush 5
ActionAdd2
ActionSetProperty
ActionEndFlag
}
從上述的ActionCode可以發現精簡了不少,其實我們可以發現它相當於如下列的程式:
onClipEvent (enterFrame)
{
setProperty("", _rotation, _rotation + 5);
}
最後我們再試著將「this」取代「double-quote」,如程式三:
程式三
onClipEvent (enterFrame)
{
setProperty(this, _rotation, _rotation + 5);
}
程式三ActionCode
onClipEvent (enterFrame)
{
ActionPush "this"
ActionGetVariable
ActionPush 10 "" 10
ActionGetProperty
ActionPush 5
ActionAdd2
ActionSetProperty
ActionEndFlag
}
從上述三個程式的ActionCode數量來看~ 若是硬要雞蛋裡挑骨頭的話,程式二在執行上應該是有較佳的效率,純屬從結果上來推論~
