我正在编写一个我兄弟正在为他正在进行的项目所需的程序。它解决了#34;一个密码,然后显示程序在找出解决方案之前经历的循环次数。我已经完成了所有工作,但程序不会在动态文本字段中显示数字。它只显示字母。
以下是代码:
import flash.events.MouseEvent;
button1.addEventListener(MouseEvent.CLICK, solvePassword);
function solvePassword(e:MouseEvent):void
{
var pass:Number = Number(inputText.text);
var attempts:Number = 0;
var i:String = pass.toString();
var passLength:Number = i.length;
var n:Number = 0;
while(n != pass)
{
if(passLength == 1)
{
n += 1;
attempts += 1;
}
if(passLength == 2)
{
n += 1;
if(n < 10) { n = 10 }
attempts += 1;
}
if(passLength == 3)
{
n+=1;
if(n < 100) { n = 100 }
attempts += 1;
}
if(passLength == 4)
{
n+=1;
if(n< 1000) { n = 1000 }
attempts += 1;
}
if(passLength == 5)
{
n+=1;
if(n < 10000) { n = 10000 }
attempts += 1;
}
if(passLength == 6)
{
n+=1;
if(n < 100000) { n = 100000 }
attempts += 1;
}
if(passLength == 7)
{
n+=1;
if(n < 1000000) { n = 1000000 }
attempts += 1;
}
}
i = "Attempts: " + String(attempts);
trace(i);
aBox.text = i;
任何信息都会有所帮助,谢谢!