我在这里尝试做的是当我点击它时按下按钮,然后当我再次单击按钮时它会移动到原始位置。然而,当我在闪光灯上运行时,按钮在我第一次单击时仅移动一次,但是当我再次单击它时它不会移回到它的位置。任何帮助都会非常感谢。
stop();
import flash.events.MouseEvent;
var step1click;
var step2click;
button1.addEventListener(MouseEvent.CLICK, positionswitch);
function positionswitch(event:MouseEvent):void
{
button1.x = 426;
button1.x = 266;
step1click = 1
}
if(step1click == 1) {
button1.addEventListener(MouseEvent.CLICK, positionswitch2);
function positionswitch2(event:MouseEvent):void
{
button1.x = 156;
button1.y = 253;
step2click = 1;
}
}
if(step2click == 1){
button1.addEventListener(MouseEvent.CLICK, positionswitch3);
function positionswitch3(event:MouseEvent):void
{
button1.x = 426;
button1.y = 266;
}
}
答案 0 :(得分:2)
尝试这样的事情:
import flash.events.MouseEvent;
stop();
var dir:Boolean=false;
button1.addEventListener(MouseEvent.CLICK, positionSwitch);
function positionSwitch(event:MouseEvent):void
{
dir =!dir;
button1.x = (dir) ? 426 : 156;
button1.y = (dir) ? 266 : 253;
}
答案 1 :(得分:0)
你可以试试这个:
stop();
import flash.events.MouseEvent;
var _clickToggle:int = 0;
var _xPos:Array = new Array(156, 426);
var _yPos:Array = new Array(253, 266);
button1.addEventListener(MouseEvent.CLICK, positionswitch);
function positionSwitch(e:MouseEvent):void {
_clickToggle = (_clickToggle + 1) % 2; // the % sign is modulo; will toggle the value between 0 and 1
button1.x = _xPos[_clickToggle];
button1.y = _yPos[_clickToggle];
}