Actionscript 3 在flash中设置边界

Actionscript 3 在flash中设置边界,actionscript-3,flash,actionscript,Actionscript 3,Flash,Actionscript,我想用as3在flash中为我的电影剪辑设置边界,这样电影剪辑就不能移出舞台。我该怎么做?这就是我现在拥有的代码。我现在如何设置边界 bij_mc.links_mc.play(); bij_mc.rechts_mc.play(); stage.addEventListener(KeyboardEvent.KEY_DOWN,beweeg); stage.addEventListener(KeyboardEvent.KEY_UP,stopbeweeg); function beweeg(

我想用as3在flash中为我的电影剪辑设置边界,这样电影剪辑就不能移出舞台。我该怎么做?这就是我现在拥有的代码。我现在如何设置边界

    bij_mc.links_mc.play();
bij_mc.rechts_mc.play();

stage.addEventListener(KeyboardEvent.KEY_DOWN,beweeg);
stage.addEventListener(KeyboardEvent.KEY_UP,stopbeweeg);

function beweeg(evt:KeyboardEvent):void {
    if (evt.keyCode==Keyboard.LEFT) {
        bij_mc.links_mc.x -=10;
        bij_mc.rechts_mc.x -=10;
        bij_mc.lichaam_mc.x -=10;
        bij_mc.links_mc.stop();
        bij_mc.rechts_mc.play();
        bij_mc.rotation = -5;
    } else if (evt.keyCode==Keyboard.RIGHT) {
        bij_mc.links_mc.x +=10;
        bij_mc.rechts_mc.x +=10;
        bij_mc.lichaam_mc.x += 10;
        bij_mc.links_mc.play();
        bij_mc.rechts_mc.stop();
        bij_mc.rotation = 5;
    } else if (evt.keyCode==Keyboard.UP) {
        bij_mc.links_mc.y -=10;
        bij_mc.rechts_mc.y -= 10;
        bij_mc.lichaam_mc.y -= 10;
        bij_mc.links_mc.play();
        bij_mc.rechts_mc.play();
        bij_mc.rotation = 0;
    } else if (evt.keyCode==Keyboard.DOWN) {
        bij_mc.links_mc.y +=10;
        bij_mc.rechts_mc.y += 10;
        bij_mc.lichaam_mc.y += 10;
        bij_mc.links_mc.stop();
        bij_mc.rechts_mc.stop();
        bij_mc.rotation = 0;
    }
}

function stopbeweeg(evt:KeyboardEvent):void {
    bij_mc.links_mc.play();
    bij_mc.rechts_mc.play();
    bij_mc.rotation = 0;
}
stage.addEventListener(Event.ENTER\u FRAME,onEnterFrame);
私有函数onEnterFrame(事件:事件):void
{
//更新beweeg
检查边界()
}
私有函数checkbounders():void
{
//左
if(bij_mc.x<0)
bij_mc.x=0;
//对
else if(bij_mc.x>舞台宽度)
bij_mc.x=舞台宽度-bij_mc.width;
//顶
if(bij_mc.y<0)
bij_mc.y=0;
//底部
否则如果(bij_mc.y>舞台高度)
bij_mc.y=舞台高度-bij_mc.height;
}

相应地更新每个电影剪辑。

你有什么想法吗?
stage.addEventListener(Event.ENTER_FRAME, onEnterFrame);
private function onEnterFrame(event:Event):void
{
   // update beweeg
   checkBoundaries()
}

private function checkBoundaries():void
{
   // left
   if (bij_mc.x < 0)
          bij_mc.x = 0;
   // right
   else if (bij_mc.x > stage.stageWidth)
          bij_mc.x = stage.stageWidth - bij_mc.width;
   // top
   if (bij_mc.y < 0)
          bij_mc.y = 0;
   // bottom
   else if (bij_mc.y > stage.stageHeight)
          bij_mc.y = stage.stageHeight - bij_mc.height;
}