我正在尝试(到目前为止没有成功)以编程方式增加和减少舞台上对象的比例。有一个 Grow 按钮 (grow_btn) 和一个 Shrink 按钮 (shrink_btn),它们随着时间的推移增加和减少选定对象(redObject、greenObject 或 blueObject)的 scaleX 和 scaleY 属性。
我遇到的问题似乎是随机的,有时只有一个属性(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);
}