在as3中在屏幕上随机添加一个对象
好的,所以我在屏幕上随机添加一个框时遇到了麻烦。我以前做过这个,看起来应该有一个相对简单的解决方案。但可惜的是,我一直无法弄清楚这一点。这是信息:
我有一个 box mc,可以导出为 Box。 我有一个 Box Actionscript 文件,其中包含以下代码:
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);
}
}
}
没有任何反应,但没有错误。我也想把一切都留在课堂上。
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:
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的代码中存在一件事,因为该代码不起作用:
1)当您使用类作为文档类时,类名称应该是唯一的,即文档类的名称不与任何库符号关联。
There is a thing in your code because of that code is not working:
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.