package {
import flash.display.MovieClip;
import flash.text.TextField;
import flash.text.TextFieldType;
import flash.events.MouseEvent;
public class coinFlip extends MovieClip {// class
var bool:Boolean;
var num1:Number;
var counter:int;
public function coinFlip() {// constructor
RandomTruth();
var textF1:TextField = new TextField();
FlipUntilHead(RandomTruth); // the error is right here*
if (bool == false) {
textF1.text = "tails";
} else {
textF1.text = "heads";
}
addChild(textF1);
function RandomTruth() {
num1 = Math.random();
//trace(num1);
if (num1 < 0.5) {
bool = false;
return;
} else {
bool = true;
return;
}
function FlipUntilHead(RandomTruth) {
while (bool == false) {
RandomTruth();
counter ++;
return
}
//trace(counter);
}
}
}// end of constructor
}// end of class
}// end of package (program)
该程序应该“翻转”一枚硬币,直到它落在正面,使用 Math.random 和布尔变量来声明它是“正面”还是“反面”。
我认为这可能是一个非常简单的错误,我只是愚蠢(编程初学者)。错误是:
“1180:调用可能未定义的方法 FlipUntilHead”