我不知道我想要的是最好用这个问题的标题来描述,但它是解释我想要完成什么的最短路。
所以我试图弄清楚如何让一个_circle从一个角落移动到一个对象的下一个角落(它在其中),但是(_circle的)运动只有在_box对象时才开始( _circle所在的那个,已停止移动,即它位于舞台的中心。 并且在同一秒钟_box正在上升,_circle停止移动并保持在它所处的位置,直到我再次点击_按钮。
我只有移动_box元素的逻辑。 (甚至那个逻辑太难看了编码/不那么优雅)
private var _myBox:Sprite = new Sprite();
private var _myCircle:Sprite = new Sprite();
private var _myButton:Sprite = new Sprite();
public function Test2()
{
addChild(_myBox);
_myBox.graphics.beginFill(0x0000FF);
_myBox.graphics.drawRect(0,0,300,100);
_myBox.graphics.endFill();
_myBox.x = stage.stageWidth * 0.5 - _myBox.width * 0.5 ;
_myBox.y = 0 - _myBox.height;
_myBox.addChild(_myCircle);
_myCircle.graphics.beginFill(0x000000);
_myCircle.graphics.drawCircle(0,0,20);
_myCircle.graphics.endFill();
_myCircle.x = 0 + _myCircle.width * 0.5;
_myCircle.y = _myCircle.height * 0.5 + _myCircle.height * 0.5;
addChild(_myButton);
_myButton.graphics.beginFill(0xAFAFAF);
_myButton.graphics.drawRect(0,0,100,100);
_myButton.graphics.endFill();
_myButton.x = 400
_myButton.y = 300
_myButton.addEventListener(MouseEvent.CLICK, onClick);
var moveBoxDown:Timer = new Timer( 1000, 1 );
moveBoxDown.addEventListener(TimerEvent.TIMER, goingDown);
moveBoxDown.start();
}
function goingDown(ev:TimerEvent):void
{
TweenLite.to( _myBox, 0.5 , {y: stage.stageHeight/2-_myBox.height/2 } );
}
private function onClick(ev:MouseEvent):void
{
var moveBoxUp:Timer = new Timer( 1000, 1 );
moveBoxUp.addEventListener(TimerEvent.TIMER, goingUp);
moveBoxUp.start();
}
function goingUp(ev:TimerEvent):void
{
TweenLite.to( _myBox, 0.5 , {y: 0 - _myBox.height } );
}
所以在我的问题上有任何帮助吗?或使代码更令人愉悦。应该非常容易。
答案 0 :(得分:1)
试试这个
function goingDown(ev:TimerEvent):void
{
TweenLite.to( _myBox, 0.5 , {y: stage.stageHeight/2-_myBox.height/2, onComplete:onTweenComplete } );
}
function onTweenComplete(ev:Event = null)
{
//Do whatever after the tween has ended
}