Question
setTimeout/setInterval
Hi there,
I designed the following code to return my application to it's Main screen when the user enters an invalid voucher number (note: they need a valid voucher number in order to be able to proceed with their purchase). I want the app to return to the Main screen after a brief 5 second time delay during which it displays an error message to the user in a dynamic text field stating that their voucher number is invalid.
Please see the code below . . .
//Define the MainSlide function . . .
function MainSlide():Void {
clearTimeout;
// GoTo Screen behavior
if((this._parent.Main != undefined) && (this._parent.Main != null))
{
var screen = null;
var target = this;
while((screen == null) && (target != undefined) && (target != null))
{
if(target instanceof mx.screens.Screen)
{
screen = target;
}
else
{
target = target._parent;
}
}
if(screen instanceof mx.screens.Slide)
{
screen.gotoSlide(this._parent.Main);
}
// End GoTo Screen behavior
}
}
//Then use it in the if statement logic . . .
// Checks the validity of VoucherNo based to the last good known Voucher Number
// and upper Voucher range (based on tomorrow's date)
if (itxtVoucherNo.length < 14) {
//changes the dynamic text field to display an "Invalid Voucher Number" message
this.dtxtVoucherNo.text = "invalid voucher number!";
//calls the MainSlide function to return the app. to the Main screen after a 5
//second delay
setTimeout(MainSlide, 5000);
// MainSlide();
}
else if (VoucherNo > this._parent.Connect_Check.PreviousValidVoucher and VoucherNo < upperVoucher) {
//if Voucher Number is valid the app. goes to the next screen
// GoTo Screen behavior
if((this._parent.Format != undefined) && (this._parent.Format != null))
{
var screen = null;
var target = this;
while((screen == null) && (target != undefined) && (target != null))
{
if(target instanceof mx.screens.Screen)
{
screen = target;
}
else
{
target = target._parent;
}
}
if(screen instanceof mx.screens.Slide)
{
screen.gotoSlide(this._parent.Format);
}
}
// End GoTo Screen behavior
trace("Voucher Number is valid!");
}
else {
//changes the dynamic text field to display an "Invalid Voucher Number" message
this.dtxtVoucherNo.text = "invalid voucher number!";
//calls the MainSlide function to return the app. to the Main screen after a 5
//second delay
setTimeout(MainSlide, 5000);
}
}
As you can see from the above code, there is a commented out line which just calls the MainSlide() function without the 5 second time delay and this logic works fine but obviously doesn't give me enough time to display my error message in my dynamic text field.
I believe that I have set this code up correctly but yet it still doesn't work. I must be doing something wrong. Can someone please take a look at this and let me know where I'm going wrong? Please!
Thanx.
I designed the following code to return my application to it's Main screen when the user enters an invalid voucher number (note: they need a valid voucher number in order to be able to proceed with their purchase). I want the app to return to the Main screen after a brief 5 second time delay during which it displays an error message to the user in a dynamic text field stating that their voucher number is invalid.
Please see the code below . . .
//Define the MainSlide function . . .
function MainSlide():Void {
clearTimeout;
// GoTo Screen behavior
if((this._parent.Main != undefined) && (this._parent.Main != null))
{
var screen = null;
var target = this;
while((screen == null) && (target != undefined) && (target != null))
{
if(target instanceof mx.screens.Screen)
{
screen = target;
}
else
{
target = target._parent;
}
}
if(screen instanceof mx.screens.Slide)
{
screen.gotoSlide(this._parent.Main);
}
// End GoTo Screen behavior
}
}
//Then use it in the if statement logic . . .
// Checks the validity of VoucherNo based to the last good known Voucher Number
// and upper Voucher range (based on tomorrow's date)
if (itxtVoucherNo.length < 14) {
//changes the dynamic text field to display an "Invalid Voucher Number" message
this.dtxtVoucherNo.text = "invalid voucher number!";
//calls the MainSlide function to return the app. to the Main screen after a 5
//second delay
setTimeout(MainSlide, 5000);
// MainSlide();
}
else if (VoucherNo > this._parent.Connect_Check.PreviousValidVoucher and VoucherNo < upperVoucher) {
//if Voucher Number is valid the app. goes to the next screen
// GoTo Screen behavior
if((this._parent.Format != undefined) && (this._parent.Format != null))
{
var screen = null;
var target = this;
while((screen == null) && (target != undefined) && (target != null))
{
if(target instanceof mx.screens.Screen)
{
screen = target;
}
else
{
target = target._parent;
}
}
if(screen instanceof mx.screens.Slide)
{
screen.gotoSlide(this._parent.Format);
}
}
// End GoTo Screen behavior
trace("Voucher Number is valid!");
}
else {
//changes the dynamic text field to display an "Invalid Voucher Number" message
this.dtxtVoucherNo.text = "invalid voucher number!";
//calls the MainSlide function to return the app. to the Main screen after a 5
//second delay
setTimeout(MainSlide, 5000);
}
}
As you can see from the above code, there is a commented out line which just calls the MainSlide() function without the 5 second time delay and this logic works fine but obviously doesn't give me enough time to display my error message in my dynamic text field.
I believe that I have set this code up correctly but yet it still doesn't work. I must be doing something wrong. Can someone please take a look at this and let me know where I'm going wrong? Please!
Thanx.