A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Is there an "exit()" type command in AS3?

  1. #1
    absolutezero3424
    Join Date
    Nov 2006
    Posts
    508

    Is there an "exit()" type command in AS3?

    is there a way to get a class to stop processing it's code as well as any utility classes it uses to stop processing their code in AS3...something like an "exit()" command or something. I want to use this if an error is generated and the whole app needs to quit. I don't want to close the window however, because prior to executing this "exit()" type command, I want to display the error message to the user and leave it up until the user closes the window.

    thx for the feedback!

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Well, there's errors. They can be thrown and caught and they interrupt processing at the point they are thrown, and you can put messages in them. I'm not quite sure what you mean by "utility classes to stop processing their code".

    If you're familiar with Java, you can draw a parallel between Errors and Exceptions.

  3. #3
    absolutezero3424
    Join Date
    Nov 2006
    Posts
    508
    well in my code, I have an IOErrorEvent or SecurityErrorEvent that triggers some actions, and I want it so that when those errors occur, the rest of the asynchronous code stops executing.

    This would include code that the Main class is executing, as well as any code in a class that the Main class uses. That's what I meant by "utility". So, for example, if Main instantiates an instance of a class called CommMgr, whatever code that is executing within CommMgr when the error occurs also would stop. Does that make sense?

    Yeah, I see what you mean by using "try, catch, throw"...can you give me an example of how I would use that? You say it does interrupt processing? Does that apply across the board to the whole app?
    Last edited by absolutezero342; 02-07-2008 at 02:05 PM.

  4. #4
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    I believe that the interruption is only to the current thread, but I'm not certain.

    Here's a trivial (untested) example
    Code:
    public class Main {
      public function Main(){
         go();
      }
    
      public function go(){
        var et:ErrorThrower = new ErrorThrower();
        try{
          for (var i:int = 0; i < 10; i++){
            trace("iteration: "+i);
            et.throwUp();
          }
        }catch(e:Error){
           trace("caught error: "+e.message);
        }
      }
    }
    Code:
    public class ErrorThrower{
      public function ErrorThrower(){}
    
      public function throwUp():void{
        throw new Error("interruption!");
      }
    }
    Running this (with appropriate includes, etc) should yield output like this:
    iteration: 0
    caught error: interruption!

    Subsequent iterations should NOT occur.

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