ActionScript3的,运动型的影片剪辑的对象运动型、影片剪辑、对象

2023-09-08 15:09:25 作者:不苟言笑

在这里,我想创建一个新的影片剪辑类型的对象,当函数mvBall被称为是感动。当我运行codeI得到这个错误:静态类型对象的值隐式强制为可能无关的类型flash.display一:影片剪辑。后来,我希望能够使球反弹回来时,它与另一个对象colides。我是新来的动作脚本,真的不知道事情是如何工作的,因此任何帮助将是AP preciated。这里的code:

 私有函数架(X:事件):无效{
        VAR球:影片剪辑=新的MovieClip();
        ball.addEventListener(Event.ENTER_FRAME,动画);
        ball.graphics.beginFill(为0xFF0000);
        ball.graphics.drawCircle(100,100,15);
        ball.graphics.endFill();
        stage.addChild(球);
    }

    私有函数动画(EV:事件):无效{
        mvBall(ev.target);
    }

    私有函数mvBall(MC:影片剪辑){
        mc.x + = 10;
    }
 

解决方案

您需要转换的目标影片剪辑

 私有函数动画(EV:事件):无效{
    mvBall(ev.target为影片剪辑);
}
 
FlashActionScript制作的一种特殊效果动画

随着中说,最好是刚刚有一个ENTER_FRAME处理,并在那里动画的对象。

  stage.addEventListener(Event.ENTER_FRAME,动画);

私有函数动画(EV:事件):无效
{
    mvBall(myBall);
    //其它物体的动画
}
 

Here i am trying to create a new movieclip type object, which is moved when function mvBall is called. When i run the code i get this err: implicit coercion of a value with static type object to a possibly unrelated type flash.display:MovieClip. Later on i want to be able to make the ball bounce back when it colides with another object. I'm new to action script and don't really know how things work so any help would be appreciated. Here's the code:

private function frame(x:Event):void {
        var ball:MovieClip = new MovieClip();
        ball.addEventListener(Event.ENTER_FRAME, animate);
        ball.graphics.beginFill(0xff0000); 
        ball.graphics.drawCircle(100, 100, 15); 
        ball.graphics.endFill(); 
        stage.addChild(ball); 
    }

    private function animate(ev:Event):void {
        mvBall(ev.target);
    }

    private function mvBall(mc:MovieClip) {
        mc.x += 10;
    }

解决方案

You need to cast the target to MovieClip

private function animate(ev:Event):void {
    mvBall(ev.target as MovieClip);
}

With that said it is better to just have one ENTER_FRAME handler and animate your objects in there.

stage.addEventListener(Event.ENTER_FRAME, animate);

private function animate(ev:Event):void
{
    mvBall(myBall);
    //other object animations
}