错误 #2007:参数文本必须为非空
Error #2007: Parameter text must be non-null
在我的程序中,用户必须输入一个介于
10 和 99,程序会将数字转换为单词。该程序有些工作;但是,当我输入一个介于 20 和 99 之间的数字时,例如 45,程序将打印出 "Forty fiveForty." 这就是 "Error #2007: Parameter text must be non-null," 出现在输出部分的时候。我似乎也无法计算 11 到 19 之间的数字。结果显示 "Error." 请编辑我的代码以使程序正常运行并正确打印出 10 到 99 之间的数字,而不是用文字显示数字。
// This line makes the button, btnConvert wait for a mouse click
// When the button is clicked, the convertNumber function is called
btnConvert.addEventListener(MouseEvent.CLICK, convertNumber);
// These lines make the textinputs wait for a mouse click
// When any of these components are clicked, the clearLabels function is called
txtinNumber.addEventListener(MouseEvent.CLICK, clearLabels);
// Declare Global Variables
var num:int; // number from 10 - 99
var tensDigit:int; // the tens digit
var onesDigit:int; // the ones digit
var teensDigit = [11, 12, 13, 14, 15, 16, 17, 18, 19];
// This is the convertNumber function
// e:MouseEvent is the click event experienced by the button
// void indicates that the function does not return a value
function convertNumber(e:MouseEvent):void
{
getData();
if (num < 10 || num > 99){
lblOutput.text = "Invalid number. Enter a number between 10 and 99 inclusive.";
}
else{
lblOutput.text = "";
if (num >= 20) {
tensDigit = Math.floor(num / 10);
onesDigit = num % 10;
tens();
ones();
}
else{
tensDigit = Math.floor(num / 10);
onesDigit = num % 10;
teens();
}
}
lblOutput.text =
tens();
lblOutput.text += onesDigit
ones();
}
// This is the getData function
// It gets the number from the user
function getData()
{
// complete the code here
num = int(txtinNumber.text);
}
// This is the tens function
// It outputs the word representation of 20, 30, 40,..,90
function tens()
{
if (tensDigit == 2 && tensDigit < 3)
{
lblOutput.text += "Twenty";
}
else if (tensDigit == 3 && tensDigit < 4)
{
lblOutput.text += "Thirty";
}
else if (tensDigit == 4 && tensDigit < 5)
{
lblOutput.text += "Forty";
}
else if (tensDigit == 5 && tensDigit < 6)
{
lblOutput.text += "Fifty";
}
else if (tensDigit == 6 && tensDigit < 7)
{
lblOutput.text += "Sixty";
}
else if (tensDigit == 7 && tensDigit < 8)
{
lblOutput.text += "Seventy";
}
else if (tensDigit == 8 && tensDigit < 9)
{
lblOutput.text += "Eighty";
}
else if (tensDigit == 9 && tensDigit < 10)
{
lblOutput.text += "Ninety";
}
else
{
lblOutput.text += "Unknown."
}
}
// This is the ones function
// It outputs the word representaion for any number from 1 - 9 inclusive
function ones()
{
if (onesDigit == 1)
{
lblOutput.text += " one"
}
else if (onesDigit == 2)
{
lblOutput.text += " two"
}
else if (onesDigit == 3)
{
lblOutput.text += " three"
}
else if (onesDigit == 4)
{
lblOutput.text += " four"
}
else if (onesDigit == 5)
{
lblOutput.text += " five"
}
else if (onesDigit == 6)
{
lblOutput.text += " six"
}
else if (onesDigit == 7)
{
lblOutput.text += " seven"
}
else if (onesDigit == 8)
{
lblOutput.text += " eight"
}
else if (onesDigit == 9)
{
lblOutput.text += " nine"
}
}
// This is the teens function
// It outputs the word representation for any number from 10 - 19 inclusive
function teens()
{
if (teensDigit == 10)
{
lblOutput.text += "Ten"
}
else if (teensDigit == 11)
{
lblOutput.text += "Eleven"
}
else if (teensDigit == 12)
{
lblOutput.text += "Twelve"
}
else if (teensDigit == 13)
{
lblOutput.text += "Thirteen"
}
else if (teensDigit == 14)
{
lblOutput.text += "Fourteen"
}
else if (teensDigit == 15)
{
lblOutput.text += "Fifteen"
}
else if (teensDigit == 16)
{
lblOutput.text += "Sixteen"
}
else if (teensDigit == 17)
{
lblOutput.text += "Seventeen"
}
else if (teensDigit == 18)
{
lblOutput.text += "Eighteen"
}
else if (teensDigit == 19)
{
lblOutput.text += "Nineteen"
}
else
{
lblOutput.text = "Error."
}
}
// This is the clearLabels function
// e:MouseEvent is the click event experienced by the textInput
// void indicates that the function does not return a value
function clearLabels(e:MouseEvent):void
{
lblOutput.text = "";
}
您引用 teensDigit
就好像它是一个 int,但您创建了一个数组。将 teens()
函数更改为
if (num == 10) {
等等,而不是teensDigit ==
或者,您可以简单地使用查找 table。以下是您尝试执行的操作的简化版本,可以在干净的项目上编译。
convertNumber(7) // Outputs: seven
convertNumber(13) // Outputs: Thirteen
convertNumber(56) // Outputs: Fifty six
function convertNumber(i:int):void {
var tens:int = Math.floor(i / 10);
var ones:int = (i > 9 && i < 20) ? i : i % 10;
trace(lookup.double[tens] + lookup.single[ones])
}
var lookup:Object = {
"single":[
"",
"one",
"two",
"three",
"four",
"five",
"six",
"seven",
"eight",
"nine",
"Ten",
"Eleven",
"Twelve",
"Thirteen",
"Fourteen",
"Fifteen",
"Sixteen",
"Seventeen",
"Eighteen",
"Nineteen"
],
"double":[
"",
"",
"Twenty ",
"Thirty ",
"Forty ",
"Fifty ",
"Sixty ",
"Seventy ",
"Eighty ",
"Ninety ",
]
}
在我的程序中,用户必须输入一个介于 10 和 99,程序会将数字转换为单词。该程序有些工作;但是,当我输入一个介于 20 和 99 之间的数字时,例如 45,程序将打印出 "Forty fiveForty." 这就是 "Error #2007: Parameter text must be non-null," 出现在输出部分的时候。我似乎也无法计算 11 到 19 之间的数字。结果显示 "Error." 请编辑我的代码以使程序正常运行并正确打印出 10 到 99 之间的数字,而不是用文字显示数字。
// This line makes the button, btnConvert wait for a mouse click
// When the button is clicked, the convertNumber function is called
btnConvert.addEventListener(MouseEvent.CLICK, convertNumber);
// These lines make the textinputs wait for a mouse click
// When any of these components are clicked, the clearLabels function is called
txtinNumber.addEventListener(MouseEvent.CLICK, clearLabels);
// Declare Global Variables
var num:int; // number from 10 - 99
var tensDigit:int; // the tens digit
var onesDigit:int; // the ones digit
var teensDigit = [11, 12, 13, 14, 15, 16, 17, 18, 19];
// This is the convertNumber function
// e:MouseEvent is the click event experienced by the button
// void indicates that the function does not return a value
function convertNumber(e:MouseEvent):void
{
getData();
if (num < 10 || num > 99){
lblOutput.text = "Invalid number. Enter a number between 10 and 99 inclusive.";
}
else{
lblOutput.text = "";
if (num >= 20) {
tensDigit = Math.floor(num / 10);
onesDigit = num % 10;
tens();
ones();
}
else{
tensDigit = Math.floor(num / 10);
onesDigit = num % 10;
teens();
}
}
lblOutput.text =
tens();
lblOutput.text += onesDigit
ones();
}
// This is the getData function
// It gets the number from the user
function getData()
{
// complete the code here
num = int(txtinNumber.text);
}
// This is the tens function
// It outputs the word representation of 20, 30, 40,..,90
function tens()
{
if (tensDigit == 2 && tensDigit < 3)
{
lblOutput.text += "Twenty";
}
else if (tensDigit == 3 && tensDigit < 4)
{
lblOutput.text += "Thirty";
}
else if (tensDigit == 4 && tensDigit < 5)
{
lblOutput.text += "Forty";
}
else if (tensDigit == 5 && tensDigit < 6)
{
lblOutput.text += "Fifty";
}
else if (tensDigit == 6 && tensDigit < 7)
{
lblOutput.text += "Sixty";
}
else if (tensDigit == 7 && tensDigit < 8)
{
lblOutput.text += "Seventy";
}
else if (tensDigit == 8 && tensDigit < 9)
{
lblOutput.text += "Eighty";
}
else if (tensDigit == 9 && tensDigit < 10)
{
lblOutput.text += "Ninety";
}
else
{
lblOutput.text += "Unknown."
}
}
// This is the ones function
// It outputs the word representaion for any number from 1 - 9 inclusive
function ones()
{
if (onesDigit == 1)
{
lblOutput.text += " one"
}
else if (onesDigit == 2)
{
lblOutput.text += " two"
}
else if (onesDigit == 3)
{
lblOutput.text += " three"
}
else if (onesDigit == 4)
{
lblOutput.text += " four"
}
else if (onesDigit == 5)
{
lblOutput.text += " five"
}
else if (onesDigit == 6)
{
lblOutput.text += " six"
}
else if (onesDigit == 7)
{
lblOutput.text += " seven"
}
else if (onesDigit == 8)
{
lblOutput.text += " eight"
}
else if (onesDigit == 9)
{
lblOutput.text += " nine"
}
}
// This is the teens function
// It outputs the word representation for any number from 10 - 19 inclusive
function teens()
{
if (teensDigit == 10)
{
lblOutput.text += "Ten"
}
else if (teensDigit == 11)
{
lblOutput.text += "Eleven"
}
else if (teensDigit == 12)
{
lblOutput.text += "Twelve"
}
else if (teensDigit == 13)
{
lblOutput.text += "Thirteen"
}
else if (teensDigit == 14)
{
lblOutput.text += "Fourteen"
}
else if (teensDigit == 15)
{
lblOutput.text += "Fifteen"
}
else if (teensDigit == 16)
{
lblOutput.text += "Sixteen"
}
else if (teensDigit == 17)
{
lblOutput.text += "Seventeen"
}
else if (teensDigit == 18)
{
lblOutput.text += "Eighteen"
}
else if (teensDigit == 19)
{
lblOutput.text += "Nineteen"
}
else
{
lblOutput.text = "Error."
}
}
// This is the clearLabels function
// e:MouseEvent is the click event experienced by the textInput
// void indicates that the function does not return a value
function clearLabels(e:MouseEvent):void
{
lblOutput.text = "";
}
您引用 teensDigit
就好像它是一个 int,但您创建了一个数组。将 teens()
函数更改为
if (num == 10) {
等等,而不是teensDigit ==
或者,您可以简单地使用查找 table。以下是您尝试执行的操作的简化版本,可以在干净的项目上编译。
convertNumber(7) // Outputs: seven
convertNumber(13) // Outputs: Thirteen
convertNumber(56) // Outputs: Fifty six
function convertNumber(i:int):void {
var tens:int = Math.floor(i / 10);
var ones:int = (i > 9 && i < 20) ? i : i % 10;
trace(lookup.double[tens] + lookup.single[ones])
}
var lookup:Object = {
"single":[
"",
"one",
"two",
"three",
"four",
"five",
"six",
"seven",
"eight",
"nine",
"Ten",
"Eleven",
"Twelve",
"Thirteen",
"Fourteen",
"Fifteen",
"Sixteen",
"Seventeen",
"Eighteen",
"Nineteen"
],
"double":[
"",
"",
"Twenty ",
"Thirty ",
"Forty ",
"Fifty ",
"Sixty ",
"Seventy ",
"Eighty ",
"Ninety ",
]
}