首页 > 办公 > Flash > 正文

游戏编程 flash.utils.Timer

2024-09-12 17:51:21
字体:
来源:转载
供稿:网友
复制代码 代码如下:

public function setNextObject() {
nextObject = new Timer(1000+Math.random()*1000,1);
nextObject.addEventListener(TimerEvent.TIMER_COMPLETE,newObject);
nextObject.start();
}
public function newObject(e:Event) {
var goodObjects:Array = ["Circle1","Circle2"];
var badObjects:Array = ["Square1","Square2"];
if (Math.random() < .5) {
var r:int = Math.floor(Math.random()*goodObjects.length);
var classRef:Class = getDefinitionByName(goodObjects[r]) as Class;
var newObject:MovieClip = new classRef();
newObject.typestr = "good";
} else {
r = Math.floor(Math.random()*badObjects.length);
classRef = getDefinitionByName(badObjects[r]) as Class;
newObject = new classRef();
newObject.typestr = "bad";
}
newObject.x = Math.random()*500;
addChild(newObject);
objects.push(newObject);
setNextObject();
}
var typeName:String = classfullname ;
var packageName:String = typeName.split("::")[1];
var type:Class = Class(getDefinitionByName(typeName));
registerClassAlias(packageName, type);
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表