【发布时间】:2012-01-24 19:50:27
【问题描述】:
在我之前的帖子Adding a object randomly on the screen in as3 中,我解释了我的具体情况。但我会再过一遍。我有一个带有类的盒子(不是我的文档类。我确实有一个叫做 Main 但这只是一个引用我的盒子的 AS 类。)类名称是 Box,我的 MC 盒子导出为 Box。这是代码
这是我在主时间线上的主文件
addEventListener(Event.ENTER_FRAME, createbox);
var _box:Box = new Box;
var boxlimit:int = 2;
function createbox (event:Event):void{
_box = new Box;
_box.x = Math.random()*stage.stageWidth ;
_box.y = Math.random()*stage.stageHeight;
addChild(_box);
}
这是我的 Box 类
//package {
// import flash.display.MovieClip;
// import flash.events.Event;
// import flash.events.MouseEvent;
//
// public class Main extends MovieClip {
//
// 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);
//
// }
// }
//}
这实际上是在我尝试上述内容之前课堂上的内容,但我宁愿将所有代码保留在课堂上。
有什么建议吗?
【问题讨论】:
-
为了确定,您想创建一个类,该类将在舞台上随机添加您的
Box库项目的新实例。所以你只需要打电话给new Box()就可以了,对吧?
标签: flash actionscript-3 actionscript flash-cs4