Actionscript 3 错误#2007:参数文本必须为非空

Actionscript 3 错误#2007:参数文本必须为非空,actionscript-3,flash,actionscript,flash-cs5,flash-cs6,Actionscript 3,Flash,Actionscript,Flash Cs5,Flash Cs6,在我的程序中,用户必须输入一个介于 10和99,程序将把数字转换成单词。这个计划有些奏效;但是,当我输入一个介于20和99之间的数字时,例如45,程序将打印出“四十五四十”。这是在输出部分出现“Error#2007:参数文本必须为非空”时。我似乎也不能让11到19之间的数字起作用。结果显示“错误”,而不是用文字显示数字。请编辑我的代码,以便程序正常运行,并正确打印出10到99之间的数字 // This line makes the button, btnConvert wait for a mo

在我的程序中,用户必须输入一个介于 10和99,程序将把数字转换成单词。这个计划有些奏效;但是,当我输入一个介于20和99之间的数字时,例如45,程序将打印出“四十五四十”。这是在输出部分出现“Error#2007:参数文本必须为非空”时。我似乎也不能让11到19之间的数字起作用。结果显示“错误”,而不是用文字显示数字。请编辑我的代码,以便程序正常运行,并正确打印出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 = "";
}
//这一行使按钮btnConvert等待鼠标单击
//单击按钮时,将调用convertNumber函数
btnConvert.addEventListener(MouseEvent.CLICK,convertNumber);
//这些行使文本输入等待鼠标单击
//单击这些组件中的任何组件时,将调用clearLabels函数
txtinNumber.addEventListener(MouseEvent.CLICK,clearLabels);
//声明全局变量
var num:int;//数字从10到99
变量数字:int;//十位数
var onesDigit:int;//一位数
var teensDigit=[11,12,13,14,15,16,17,18,19];
//这是convertNumber函数
//e:MouseEvent是按钮所经历的单击事件
//void表示函数不返回值
函数convertNumber(e:MouseEvent):void
{ 
getData();
如果(num<10 | | num>99){
lblOutput.text=“无效数字。请输入一个介于10和99之间(含10和99)的数字。”;
}
否则{
lblOutput.text=“”;
如果(数值>=20){
tensDigit=数学楼层(num/10);
onesDigit=num%10;
十;
一个();
}
否则{
tensDigit=数学楼层(num/10);
onesDigit=num%10;
青少年();
}
}
lblOutput.text=
十;
lblOutput.text+=onesDigit
一个();
}
//这是getData函数
//它从用户那里获取数字
函数getData()
{
//在这里完成代码
num=int(txtinNumber.text);
}
//这是tens函数
//它输出20、30、40、…、90的单词表示
函数tens()
{
如果(tensDigit==2&&tensDigit<3)
{
lblOutput.text+=“二十”;
}
否则如果(tensDigit==3&&tensDigit<4)
{
lblOutput.text+=“三十”;
}
else if(tensDigit==4&&tensDigit<5)
{
lblOutput.text+=“四十”;
}
否则如果(tensDigit==5&&tensDigit<6)
{
lblOutput.text+=“五十”;
}
else if(tensDigit==6&&tensDigit<7)
{
lblOutput.text+=“六十”;
}
else if(tensDigit==7&&tensDigit<8)
{
lblOutput.text+=“七十”;
}
else if(tensDigit==8&&tensDigit<9)
{
lblOutput.text+=“八十”;
}
否则如果(tensDigit==9&&tensDigit<10)
{
lblOutput.text+=“九十”;
}
其他的
{
lblOutput.text+=“未知。”
}
}
//这就是我们的功能
//它输出1-9(含1-9)中任意数字的单词表示
函数一()
{
如果(onesDigit==1)
{
lblOutput.text+=“一个”
}
else if(onesDigit==2)
{
lblOutput.text+=“两个”
}
else if(onesDigit==3)
{
lblOutput.text+=“三个”
}
else if(onesDigit==4)
{
lblOutput.text+=“四个”
}
else if(onesDigit==5)
{
lblOutput.text+=“五”
}
else if(onesDigit==6)
{
lblOutput.text+=“六个”
}
else if(onesDigit==7)
{
lblOutput.text+=“七”
}
else if(onesDigit==8)
{
lblOutput.text+=“八”
}
else if(onesDigit==9)
{
lblOutput.text+=“九”
}
}
//这是青少年功能
//它输出10-19(含10-19)之间任意数字的单词表示
函数()
{
如果(teensDigit==10)
{
lblOutput.text+=“十”
}
else if(teensDigit==11)
{
lblOutput.text+=“十一”
}
else if(teensDigit==12)
{
lblOutput.text+=“十二”
}
else if(teensDigit==13)
{
lblOutput.text+=“十三”
}
else if(teensDigit==14)
{
lblOutput.text+=“十四”
}
否则如果(teensDigit==15)
{
lblOutput.text+=“十五”
}
else if(teensDigit==16)
{
lblOutput.text+=“十六”
}
else if(teensDigit==17)
{
lblOutput.text+=“十七”
}
else if(teensDigit==18)
{
lblOutput.text+=“十八”
}
else if(teensDigit==19)
{
lblOutput.text+=“十九”
}
其他的
{
lblOutput.text=“错误。”
}
}
//这是clearLabels函数
//e:MouseEvent是textInput所经历的单击事件
//void表示函数不返回值
函数clearLabels(e:MouseeEvent):void
{
lblOutput.text=“”;
}

您引用的是
teensDigit
,好像它是一个int,但您创建了一个数组。将
teents()
函数更改为

if (num == 10) {
依此类推,而不是
teensDigit==


或者,您可以简单地使用查找表。下面是您尝试执行的操作的简化版本,可以在干净的项目上进行编译

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 ",
    ]
}
convertNumber(7)//输出:7
convertNumber(13)//输出:13
convertNumber(56)//输出:56
函数convertNumber(i:int):void{
变量十:整数=数学楼层(i/10);
变量1:int=(i>9&&i<20)?i:i%10;
跟踪(查找。双[十]+查找。单[一])
}
变量查找:对象={
“单身”:[
"",
“一个”,
“两个”,
“三”,
“四”,
“五个”,
“六”,
“七”,
“八”,
“九”,
“十”,
“十一”,
“十二”,
“十三”,
“十四”,
“十五”,