-
Senior Member
Is it possible break a script in Flash? Say i'm running about 20 lines, halfway something happens and I want the script to stop at line ten and exit. Is this at all possible?
-
Senior Member
A bit of structured programming, maybe
Code:
if(Something happens) {
//do this code
}
Anything else and it won't..
-
there is a break command, this may do what you want. It's concidered bad practise by some people though
-
Senior Member
If you were felling crude you could use break; But if it doesn't always need to exit there, you're going to need an if() statement. If it does, whats the point of having code there at all?
-
Senior Member
Okay this was my purpose, this code lies on a button:
<b>ORIGINAL:</b>
on(press){
if(var == 1){
var = 2;
this.happen;
}
if(var == 2){
var = 1;
this.happen;
}
}
<b>POSSIBLE SOLUTION:</b>
on(press){
if(var == 1){
var = 2;
this.happen;
break;
}
if(var == 2){
var = 1;
this.happen;
}
}
-
Senior Member
Ohh,
You just need
Code:
on(press){
if(var == 1){
var = 2;
this.happen;
}else if(var == 2){
var = 1;
this.happen;
}
}
Just an else if
-
Senior Member
but would that still work as the else would happen because var has become 2? The second bit of code musn't execute if the first if statement is true. I could use another variable but I was trying to think of a more efficient way of doing this
BTW, how do u put that code:______ thing in for script?
-
Senior Member
Nope, that will work. Open up a new movie and put this in
Code:
myVar = 1;
if(myVar == 1) {
trace("first");
myVar = 2;
}else if(myVar == 2) {
trace("second");
myVar = 1;
}
That's the whole points of using else, once it enters one bit, it "breaks" itself, not entering anything other bit, whatever you have changed.
(Take a look at vB Code link at top of page)
-
I would use a switch statement:
switch (var)
{
case 1:
var = 2
this.happen
break
case 2:
var=1
this.happen
break
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|