A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: Can you break a script?

  1. #1
    Senior Member Wancieho's Avatar
    Join Date
    May 2002
    Posts
    370
    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?

  2. #2
    Senior Member chi-styler's Avatar
    Join Date
    Jul 2001
    Location
    Bristol, UK
    Posts
    1,237
    A bit of structured programming, maybe

    Code:
    if(Something happens) {
      //do this code
    }
    Anything else and it won't..

  3. #3
    Senior Member
    Join Date
    Mar 2002
    Posts
    298
    there is a break command, this may do what you want. It's concidered bad practise by some people though

  4. #4
    Senior Member chi-styler's Avatar
    Join Date
    Jul 2001
    Location
    Bristol, UK
    Posts
    1,237
    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?

  5. #5
    Senior Member Wancieho's Avatar
    Join Date
    May 2002
    Posts
    370
    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;
    }
    }

  6. #6
    Senior Member chi-styler's Avatar
    Join Date
    Jul 2001
    Location
    Bristol, UK
    Posts
    1,237
    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

  7. #7
    Senior Member Wancieho's Avatar
    Join Date
    May 2002
    Posts
    370
    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?

  8. #8
    Senior Member chi-styler's Avatar
    Join Date
    Jul 2001
    Location
    Bristol, UK
    Posts
    1,237
    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)

  9. #9
    Senior Member
    Join Date
    Mar 2002
    Posts
    298
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center