• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 201
  • Last Modified:

textfield not updating fast enough

I am having trouble with the pause thats created, occuring before the textField(form_error) can update.  Any way to force textField component to update before more code executes?


private function changePasswordRemotingResult (r:ResultEvent):Void {
    if(r.result == true) {
        changePassword_bool = false;
        form_error.textColor = 0x0066CC;
        form_error.text = "Password changed successfully";
       
        //create pause by actionscript
        var pTime:Number = 2;
        var sTime:Number = new Date();
        var sSec:Number = sTime.getTime();
        var cont:Boolean = false;
        while (not cont) {
            var nTime:Date = new Date();
            var nSec:Number = nTime.getTime();
            if (nSec>(sSec+(pTime*1000))) {
                cont = true;
            }
        }
        loginUser();
    }
    else {
        loginError("Error: Trouble updating database");
    }
}
0
gmailrules
Asked:
gmailrules
  • 5
  • 4
  • 2
1 Solution
 
vickerleungCommented:
gmailrules

What I suggest here is to seperate it into two functions instead of using while count
Because the continuous while loop may cause large system resource consumption and is redundant

So you better seperate it into two parts

First part, execute e.g. in frame 1
private function changePasswordRemotingResult (r:ResultEvent):Void {
    if(r.result == true) {
        changePassword_bool = false;
        form_error.textColor = 0x0066CC;
        form_error.text = "Password changed successfully";
    }
    else {
        loginError("Error: Trouble updating database");
    }
}

Second part, execute e.g. in frame 20 (which is 2 seconds later)

loginUser();

Vicker
0
 
gmailrulesAuthor Commented:
this is all in a class so i cant execute the other part in another frame.  i have to use actionscript to make the pause.
0
 
vickerleungCommented:
gmailrule

ok then

is it some kind of coding problem

        while (not cont) {
            var nTime:Date = new Date();
            var nSec:Number = nTime.getTime();
            if (nSec>(sSec+(pTime*1000))) {
                cont = true;
                loginUser ();
            }
        }

Will this modification work?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
gmailrulesAuthor Commented:
i don't believe it's a coding problem.  The pause works it's just that the form textfield does not update before the pause for some reason.  even though i set it to update before the pause, it doesnt change till after.


        form_error.text = "Password changed successfully";  //doesnt update till after the pause below is completed
       
        //create pause by actionscript
        var pTime:Number = 2;
        var sTime:Number = new Date();
        var sSec:Number = sTime.getTime();
        var cont:Boolean = false;
        while (not cont) {
            var nTime:Date = new Date();
            var nSec:Number = nTime.getTime();
            if (nSec>(sSec+(pTime*1000))) {
                cont = true;
            }
        }
0
 
vickerleungCommented:
gmailrules,

Finally got your meaning~ I am sorry that I misunderstand you

Try the following, maybe the logic is a little bit stupid, but it may work

var updated:Boolean = false;

while (not updated)
{
      if (form_error.text != "Password changed successfully")
      {
            form_error.text = "Password changed successfully";
      }
      else
      {
            updated = true;

               var pTime:Number = 2;
               var sTime:Number = new Date();
              var sSec:Number = sTime.getTime();
              var cont:Boolean = false;
              while (not cont)
            {
                        var nTime:Date = new Date();
                        var nSec:Number = nTime.getTime();
                        if (nSec>(sSec+(pTime*1000)))
                  {
                            cont = true;
                        }
              }
      }
}

loginUser ();
0
 
gmailrulesAuthor Commented:
it didn't work.  i think the value gets changed but it doesnt update on the stage fast enough before it enters the pause
0
 
vickerleungCommented:
Is quite funny then, usually setting text should be an immediate process

Would you mind send me your fla?
vickerleung@hotmail.com

Thanks
0
 
DavidCrossmanCommented:
gmailrules:

Don't know if you are still looking for an answer, but here's one for you.

This is an update problem with Flash.

Basically, you are asking the file to update information faster than the frame rate and the only way to do that is with updateAfterEvent(). But, updateAfterEvent only works with intervals and mouse listeners.

My suggestion would be to remove the count and the call to loginUser() and replace with the following:

changePasswordInt = setInterval(nowLogin, 250);
function nowLogin() {
clearInterval(changePasswordInt);
loginUser();
}

This forces Flash to allow the system to update, as more time will pass than needed for a frame to elapse.

Hope this helps!

David Crossman
-=-
0
 
gmailrulesAuthor Commented:
Yes, I am still looking for the anwser to this one :)  I tried your solution but could not get it to work properly.

private function whatever():Void {
    _root.changePasswordInt = setInterval(nowLogin, 250);
}

function nowLogin() {
    clearInterval(_root.changePasswordInt);
    loginUser();
}

I was able to get it to go through the interval once with the above code but it does not execute the loginUser() function for some reason.


private function whatever():Void {
    _root.changePasswordInt = setInterval(nowLogin, 250);
    loginUser();
}

function nowLogin() {
    clearInterval(_root.changePasswordInt);
}

the above modification did not work either.  it executed loginUser() but the interval happened afterwards.  I used trace statements to verify.


Thanks for the help,

John
0
 
DavidCrossmanCommented:
John,

What you wrote here:

    private function whatever():Void {
        _root.changePasswordInt = setInterval(nowLogin, 250);
    }

    function nowLogin() {
        clearInterval(_root.changePasswordInt);
        loginUser();
    }

is correct.

Let's change the declaration of the second function to match standards from "function nowLogin" to "private function nowLogin():Void". Drop a trace into nowLogin to confirm that it is firing. (Will also tell you if the clearInterval isn't working, by continuing to fire...)

If still having problems, try changing loginUser() to this.loginUser() or _root.loginUser(), make an explicit call to the function.

Better yet, change the interval call to:
setInterval(nowLogin, 250, this);  //THIS is then a parameter sent to nowLogin. Could be any valid reference to the object that includes loginUser().

then change nowLogin to function nowLogin(objRef:Object).

The statement within nowLogin can be
objRef.loginUser();

Hopefully, this makes sense.

Best of luck!

David Crossman
-=-
0
 
gmailrulesAuthor Commented:
passing the object reference worked!  Thanks a lot!  I was wondering if this question would ever be close :-)

Thanks,

John
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 5
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now