1

出于某种原因,我的值没有在函数之外更新。我正在尝试制作一个按钮,例如“加号”,不断向上移动影片剪辑“topArrow”。我认为布尔值是触发它的一种简单方法,但它不会在函数之外进行更新。为什么是这样?

import flash.events.Event;
import flash.events.MouseEvent;

var speed:Number = 1;

plus.addEventListener(MouseEvent.MOUSE_DOWN, arrow_up);
plus.addEventListener(MouseEvent.MOUSE_UP, arrow_stop);
minus.addEventListener(MouseEvent.MOUSE_DOWN, arrow_down);
minus.addEventListener(MouseEvent.MOUSE_UP, arrow_stop);

var move_up:Boolean = false;
var move_down:Boolean = false;



function arrow_up(event:MouseEvent):void
{
    trace("button pressed");
    move_up = true;
}


function arrow_stop(event:MouseEvent):void
{

    move_up = false;
    move_down = false;
}

function arrow_down(event:MouseEvent):void
{

    move_down = true;
}

while (move_up==true)
{
    topArrow.y +=  speed;
}

while (move_down==true)
{
    topArrow.y -=  speed;
}

if(move_up)
{
    trace("true");
}
4

2 回答 2

1

那些while循环很可怕,一旦move_up为真,它会进入那个循环并且永远不会退出?

我会做类似下面的事情来动画电影剪辑:

var speed:Number = 1;

plus.addEventListener(MouseEvent.MOUSE_DOWN, arrow_up);
plus.addEventListener(MouseEvent.MOUSE_UP, arrow_stop);
minus.addEventListener(MouseEvent.MOUSE_DOWN, arrow_down);
minus.addEventListener(MouseEvent.MOUSE_UP, arrow_stop);

stage.addEventListener(Event.ENTER_FRAME, onEnterFrame);

var move_up:Boolean = false;
var move_down:Boolean = false;

function arrow_up(event:MouseEvent):void
{
    trace("button pressed");
    move_up = true;
}

function arrow_stop(event:MouseEvent):void
{
    move_up = false;
    move_down = false;
}

function arrow_down(event:MouseEvent):void
{
    move_down = true;
}

function onEnterFrame(event:Event):void
{
   if(move_up)
       topArrow.y += speed;
   else if(move_down)
       topArrow.y -=speed;

   if(move_up)
   {
      trace("true");
   }
}
于 2013-03-03T04:53:34.703 回答
-1

反编译二进制文件并查看 move_up setter 函数。

于 2013-03-04T12:49:45.303 回答