Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 在变量中存储y坐标_Actionscript 3_Flash_Variables_Actionscript_Coordinates - Fatal编程技术网

Actionscript 3 在变量中存储y坐标

Actionscript 3 在变量中存储y坐标,actionscript-3,flash,variables,actionscript,coordinates,Actionscript 3,Flash,Variables,Actionscript,Coordinates,我正试图用鼠标点击一个电影剪辑的y位置。到目前为止,我有这个代码 import fl.transitions.Tween; import fl.transitions.easing.*; var posY:Number = infographic_mc.y var redY:Number = -232 var orangeY:Number = -551 var yellowY:Number = -883 var greenY:Number = -1225 var blueY:Number

我正试图用鼠标点击一个电影剪辑的y位置。到目前为止,我有这个代码

import fl.transitions.Tween;

import fl.transitions.easing.*;


var posY:Number = infographic_mc.y
var redY:Number = -232
var orangeY:Number = -551
var yellowY:Number = -883
var greenY:Number = -1225
var blueY:Number = -1543
var purpleY:Number = -1873

var tween1:Tween = new Tween(infographic_mc, "y", Regular.easeOut, posY, redY, 2, true);
var tween2:Tween = new Tween(infographic_mc, "y", Regular.easeOut, posY, orangeY, 2, true);
var tween3:Tween = new Tween(infographic_mc, "y", Regular.easeOut, posY, yellowY, 2, true);
var tween4:Tween = new Tween(infographic_mc, "y", Regular.easeOut, posY, greenY, 2, true);
var tween5:Tween = new Tween(infographic_mc, "y", Regular.easeOut, posY, blueY, 2, true);
var tween6:Tween = new Tween(infographic_mc, "y", Regular.easeOut, posY, purpleY, 2, true);

tween1.stop();
tween2.stop();
tween3.stop();
tween4.stop();
tween5.stop();
tween6.stop();

red_btn.addEventListener(MouseEvent.CLICK, redButtonClick);  
orange_btn.addEventListener(MouseEvent.CLICK, orangeButtonClick);  
yellow_btn.addEventListener(MouseEvent.CLICK, yellowButtonClick);  
green_btn.addEventListener(MouseEvent.CLICK, greenButtonClick);  
blue_btn.addEventListener(MouseEvent.CLICK, blueButtonClick);  
purple_btn.addEventListener(MouseEvent.CLICK, purpleButtonClick);  


function redButtonClick(event:MouseEvent):void {

tween1.start();

 }


function orangeButtonClick(event:MouseEvent):void {

tween2.start();
}


function yellowButtonClick(event:MouseEvent):void {

tween3.start();
}


function greenButtonClick(event:MouseEvent):void {

tween4.start();
}


function blueButtonClick(event:MouseEvent):void {

tween5.start();
}


function purpleButtonClick(event:MouseEvent):void {

tween6.start();
}
这是可行的,但它不会在一个tween之后存储Y坐标,并且每个tween都返回到开始


有没有办法更新在鼠标单击函数中存储Y坐标的变量?

您可以使用一个变量来存储当前的Y坐标,而不是在开始时创建所有的Y坐标

var currentTween:Tween; 
然后,在每个事件侦听器中,您可以根据信息图的当前位置创建您当前的tween。代码如下所示:

function redButtonClick(event:MouseEvent):void {
   if(currentTween) currentTween.stop(); //if there is a current tween animating, stop it

   currentTween = new Tween(infographic_mc, "y", Regular.easeOut, infographic_mc.y, redY, 2, true);

   currentTween.start();
}
此外,我建议为所有按钮使用一个处理函数,而不是单独的函数,并使用switch语句来确定单击了哪个按钮。此外,如果您计划在应用程序中使用大量动画,请查看GreenSock库中的tweening,因为它具有更好的性能