ActionScript3的,运动型的影片剪辑的对象 [英] ActionScript3, moving objects of type movieclip

查看:116
本文介绍了ActionScript3的,运动型的影片剪辑的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里,我想创建一个新的影片剪辑类型的对象,当函数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为影片剪辑);
}
 

随着中说,最好是刚刚有一个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
}

这篇关于ActionScript3的,运动型的影片剪辑的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆