我試圖(迄今不成功)以編程方式增加和減少舞臺上的對象的比例。有一個Grow按鈕(grow_btn)和一個Shrink按鈕(shrink_btn),可以隨着時間的推移增加和減少選定對象(redObject,greenObject或blueObject)的scaleX和scaleY屬性。Actionscript 3.0 Tween錯誤
我遇到的問題似乎是隨機的,有時只有一個屬性(scaleX或scaleY)會改變,而另一個不會。另外,補間函數的目標和原始大小不能正確調整。例如:1.0幾乎是舞臺上的對象的兩倍。
//Imports
import fl.transitions.Tween;
import fl.transitions.easing.*;
//Constants And Variables
const starRotationAngle:Number = 0.5;
const starSpeed:Number = 2;
var moveForward:Boolean = true;
var selectedObject:MovieClip;
//Event Listeners & Functions
star_mc.addEventListener(MouseEvent.CLICK, rotateStar);
function rotateStar(e:MouseEvent):void
{
star_mc.rotation += 5;
}
addEventListener(Event.ENTER_FRAME, starMove);
function starMove(e:Event):void
{
if (star_mc.x >= stage.stageWidth + star_mc.width)
{moveForward = false;}
else if (star_mc.x <= stage.x - star_mc.width)
{moveForward = true;}
if (moveForward == true)
{
star_mc.x += starSpeed;
star_mc.rotation += starRotationAngle;
}
else
{
star_mc.x -= starSpeed;
star_mc.rotation -= starRotationAngle;
}
}
redObject.addEventListener(MouseEvent.CLICK, changeSelectedObjectVariable);
greenObject.addEventListener(MouseEvent.CLICK, changeSelectedObjectVariable);
blueObject.addEventListener(MouseEvent.CLICK, changeSelectedObjectVariable);
function changeSelectedObjectVariable(e:MouseEvent):void
{
selectedObject = e.currentTarget as MovieClip;
}
grow_btn.addEventListener(MouseEvent.CLICK, grow);
function grow(e:MouseEvent):void
{
var tweenGrowX:Tween = new Tween(selectedObject, "scaleX", None.easeIn, 1.0, 2.0, 3.0, true);
var tweenGrowY:Tween = new Tween(selectedObject, "scaleY", None.easeIn, 1.0, 2.0, 3.0, true);
}
shrink_btn.addEventListener(MouseEvent.CLICK, shrink);
function shrink(e:MouseEvent):void
{
var tweenShrinkX:Tween = new Tween(selectedObject, "scaleX", None.easeIn, 2.0, 1.0, 3.0, true);
var tweenShrinkY:Tween = new Tween(selectedObject, "scaleY", None.easeIn, 2.0, 1.0, 3.0, true);
}
謝謝。就是這樣。 :) – TheDarkIn1978 2010-02-21 07:09:49
wpjmurray謝謝你的好解釋。我知道垃圾收集,但完全錯過了2個變量變量的範圍可能導致的問題。 – 2010-02-21 20:39:29