我目前有一个实例名称为“powerbar”的MovieClip。它总共有6个帧,根据某个标准,我希望它显示一个特定的帧。这是我的代码:
if(char.throwing) {
var pressLength:Number = getTimer()-startPress;
if(pressLength >= 400) {
powerbar.gotoAndPlay(6);
trace("more than 400 " +String(powerbar.currentFrame));
}
else if(pressLength >= 300) {
powerbar.gotoAndPlay(5);
trace("more than 300 " +String(powerbar.currentFrame));
}
else if(pressLength >= 200) {
powerbar.gotoAndPlay(4);
trace("more than 200 " +String(powerbar.currentFrame));
}
else if(pressLength >= 100) {
powerbar.gotoAndPlay(3);
trace("more than 100 " +String(powerbar.currentFrame));
}
else if(pressLength >= 50) {
powerbar.gotoAndPlay(2);
trace("more than 50 " +String(powerbar.currentFrame));
}
else if(pressLength >= 25) {
powerbar.gotoAndPlay(1);
trace("more than 25 " +String(powerbar.currentFrame));
}
else if(pressLength >= 0) {
powerbar.gotoAndPlay(1);
}
它编译得很好,在运行时没有错误,我甚至检查我的if语句是否正常工作取决于我需要的东西,我确保我引用了正确的影片剪辑(我追踪了影片剪辑的x位置,这是正确的)。我甚至跟踪它是否通过跟踪(power bar.currentFrame)进入该帧,并且它显示它已经进展到该帧,尽管它没有在动画中显示。 我也试过gotoAndStop,但它仍然没有用...... 请帮助!
答案 0 :(得分:0)
var pressLength:Number = getTimer()-startPress;
//enterFrame/or keypress function here:)
if(char.throwing) {
throwing_function();
}
function throwing_function (){
if(pressLength >= 25 && pressLength<=49) { // check both conditions
powerbar.gotoAndStop(2);
trace("more than 25 but less than 50")
trace(pressLength.toString) // i think
}
else if(pressLength >= 50 && pressLenght<=74) {check both conditions are good
powerbar.gotoAndStop(3);
trace("more than 50 but less than 75 ")
}
}
etc......
但有更好的方法来解决这个问题,我想我会坚持你的主题
通过只检查一个条件你有问题,我很久以前在加载资产的进度条上犯了这个错误。