在AS3在屏幕上添加一个对象随机 [英] Adding a object randomly on the screen in as3

查看:143
本文介绍了在AS3在屏幕上添加一个对象随机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好了,所以我有在屏幕上添加一个箱子随机麻烦。我以前这样做,好像它应该有一个相对简单的解决方案。但是,唉,我一直没能想出解决办法。这是信息:

OK, so i am having trouble with adding a box randomly on the screen. I have done this before and it seems like it should have a relatively easy solution. But alas, i have not been able to figure this out. This is the info:

我有一个盒子三菱商事与出口的箱。 我有一个盒子的ActionScript文件,该code。在它:

I have a box mc with exporting as Box. I have a Box Actionscript file with this code in it:

package {
    import flash.display.MovieClip;
    import flash.events.Event;
    import flash.events.MouseEvent;
public class Box extends MovieClip {

    public function Box() {
        createBox();

    }

    private function createBox():void {

        var _box:Box = new Box();
        _box.x = Math.random()*stage.stageWidth ;
        _box.y = Math.random()*stage.stageHeight;
        stage.addChild(_box);

    }
}
}

什么都没有发生,但没有错误。此外,我想保持一切类。

Nothing happens at all but there is no errors. Also i would like to keep everything in the classes.

推荐答案

有原因在于,code在code的事情是行不通的:

There is a thing in your code because of that code is not working:

文档类1)当您使用类作为文档类,那么类名称应该是唯一的,即名称不与任何库符号相关联的。

1) when you are using class as a Document class then the class name should be unique i.e name of Document class is not associated with any library symbols.

package   
{
    import flash.display.MovieClip;  
    import flash.events.Event;  
    import flash.events.MouseEvent;  

    public class Main extends MovieClip 
    {
        private var _box:Box = new Box();

        public function Main() 
        {
            createBox();
        }

        private function createBox():void 
        {
            trace(Math.random()*stage.stageWidth)
            _box.x = Math.random()*stage.stageWidth ;
            _box.y = Math.random()*stage.stageHeight;
            stage.addChild(_box);   
        }
    }
}

这篇关于在AS3在屏幕上添加一个对象随机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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