How to exit AS?

Hi,
How do I exit a script in case a condition is f.ex. true ?
Let’s say I have following script:

on (release) {

if (!psw2_fla) {
inf= “Insert password !” ;
// HERE I WANT TO EXIT SINCE MY MESSAGE WILL NOT BE SHOWN…
//IT WILL BE OVERWRITTEN DUE TO THE CONDITION BELOW !
// THAT IS IT WILL SAY: Wrong password !
}

if (psw2_fla == “hello”) {
inf= “Welcome” ;

} else {
inf= “Wrong password !” ;
}

}

I think you end with the } thing.


on (release) {
     if (!psw2_fla) {
          inf= "Insert password !" ;
     }
     else if (psw2_fla == "hello") {
          inf= "Welcome" ;
     } 
     else {
         inf= "Wrong password !" ;
     }
}

you have two seperate ‘if’ statements. So that means that you have two seperate checks. You should connect all if’s so that if one is true, you would then exit the code.

How do you do this you ask!

well, like so:

if(condition 1)
{

}
else if(condition 2)
{

}
else if (condition 3)
{

}
else//you dont need to end with this else! if you must add a condition, you use 'else if'
{

}

Hi,
Thanks for the replies.

Your suggestions seems quite logic ,but if I compare to VBA progamming it doesn´t look simple. I can also do the same in VBA but what I was looking for is something like this (VBA Example):

if textbox1="" then
msgbox "Please insert your password !"
exit sub
end if

if textbox1=“Hello” then
msgbox "Welcome "
end if

ALTERNATIVE:

if textbox1="" then
msgbox "Please insert your password !"
goto line10:
end if

if textbox1=“Hello” then
msgbox "Welcome "
end if

line10:

The fact I inserted exit sub above ensures me the code will not proceed but will exit the script. Second example will goto line10: thus passing the second if-then condition.
That means I can have a section where I ensure values are inserted in the boxed before I proceed to elaborate the input.

I agree your suggestion gives me the result but it should be easier ?
Thus I am looking for a exit or goto statement within the ActionScript?

best regards

that is the easy way! I think you are making this much more complicated that it is!
I assume you have a submit button, yes? When you press submit, the code chacks to see which input boxes are empty, if any, them produce an error massege.

Having said that, you can have another way, in which you add listeners to you input boxes. Every time you exit an input box, the listener fires up, and does whatever you want (eg. checks the input within that box). The difference here is that the input checking/testing happens as soon as you leave the input box, and not all at once when you click the submit button.

I hope this is what you need :slight_smile:

Hi,
Thanks for the input. That sounds very interesting. I would like to try your idea but…what do I do then ? I am new to Flash but fully understand the scripts so if you could give me some more input on this ? (programmed VBA/ SQL for 7 years now)

This will also solve a problem, I have in trying to control what input box next to have focus after exiting an input box (i.e. tab order) ?

Best regards

Hi,
I think it takes some time to get the point of listeners, thus I have looked for information. I found something at:
http://www.actionscript4designers.com/wmg3/input_text_enter_key.html

I will work with this, but if you should have some ‘short cut’ information, I would appreciate it.

Best regards