【发布时间】:2011-06-14 03:12:21
【问题描述】:
我一直在关注为 Actionscript 2 编写的教程,并已成功将其转换为 AS 3,但是在倒数第二部分我被卡住了。
这里的教程(http://www.cleverpig.com/tutorials/whackapig/whack.htm step 8)有以下代码:
if (_currentframe==1) {
// randomly choose whether or not to play
if (random(100)>97) {
// should we tease or popup?
if (random(3)<1) {
this.gotoAndPlay ("popup");
} else {
this.gotoAndPlay (1);
}
}
}
它旨在为角色的移动添加一些随机性。经过一番谷歌搜索后,我在 AS 3 中创建了这段代码,希望它能正常工作。
if (currentFrame==1) {
// randomly choose whether or not to play
if(Math.floor(Math.random()*99)-97) {
// should we tease or popup?
if (Math.floor(Math.random() *3)-1)
) {
this.gotoAndPlay ("popup");
} else {
this.gotoAndPlay (1);
}
}
}
当我使用此代码运行程序时,角色的整个动画播放一次(向下、半向上、向上、撞击)。它应该只播放前 3 帧,然后重复。
编辑:
function random (n:int ) : int {
return Math.floor (Math.random() * n);
}
if (currentFrame==1) {
// randomly choose whether or not to play
if(random(100)): 97 {
// should we tease or popup?
if (random(3)): 1
{
this.gotoAndPlay ("popup");
} else {
this.gotoAndPlay (1);
}
}
}
符号“洞”,层“Actionscript”,第 1 帧,第 10 行 1084:语法错误:需要冒号前的标识符。 符号 'hole',图层 'Actionscript',第 1 帧,第 10 行 1008:属性无效。 符号 'hole',图层 'Actionscript',第 1 帧,第 12 行 1084:语法错误:在冒号之前需要标识符。 符号 'hole',图层 'Actionscript',第 1 帧,第 13 行 1008:属性无效。 符号 'hole',图层 'Actionscript',第 1 帧,第 15 行 1083:语法错误:否则是意外的。
【问题讨论】:
标签: flash actionscript-3 math actionscript random