0

我在这里尝试做的是在我单击它时使按钮移动,然后当我再次单击该按钮时它会移动到原始位置。但是,当我在 Flash 上运行此按钮时,当我第一次单击它时,该按钮仅移动一次,但是当我再次单击它时,它不会移回其位置。任何帮助都会非常感谢。

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;
    }
}
4

2 回答 2

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;
}
于 2013-08-06T13:13:09.273 回答
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];
}
于 2013-08-06T13:16:02.047 回答