dimanche 21 février 2016

AS3 - Numbers won't display in dynamic text field

I am writing a program that my brother needs for a project he is working on. It "solves" a password and then shows the number of loops the program goes through before figuring out the solution. I've gotten everything working but the program won't show the numbers in the dynamic text field. It only shows the letters.

Here's the code:

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;

Any info would help, thank you!

Aucun commentaire:

Enregistrer un commentaire