• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

Handling runtime errors

Participant ,
Nov 12, 2010 Nov 12, 2010

Copy link to clipboard

Copied

We have an AS3 application made in Flash Builder that I would like to compile such that the script continues to execute after encountering a runtime error.

We made a simple AS3 test movie and compiled it with Flash CS3 and then Flash Builder.

The movie tries to evaluate a variable that does not exist, and then puts a yellow square on the stage.

Here is the core of the code:

if(this["d"] == 1){ } // this line throws a runtime error because d is not declared.

var s:Sprite = new Sprite();

s.graphics.beginFill(0xFFCC00);

s.graphics.drawRect(0,0,200,200);

addChild(s);

In the movie compiled in CS3 (with this code in a frame on the timeline) the runtime error seems to be ignored - and the square appears.

In the movie compiled in FB with this code wrapped in a simple Class, or if this class is used as the document class for a CS3 movie - then the resulting swf throws the runtime error and does not add the sprite to the stage.

Here is the simple Class:

package

{

import flash.display.MovieClip;

import flash.display.Sprite;

public class ErrorTest extends MovieClip

{

public function ErrorTest()

{

if(this["d"] == 1){ } // this line throws a runtime error because d is not declared.

var s:Sprite = new Sprite();

s.graphics.beginFill(0xFFCC00);

s.graphics.drawRect(0,0,200,200);

addChild(s);

}

}

}

Why does it ignore the error when I just publish this code on the timeline?

How can we compile a swf that will emulate this behavior using class files?

Does the timeline code extend a class that ignores runtime errors?

We read this http://livedocs.adobe.com/flex/3/html/help.html?content=11_Handling_er rors_03.html and it seems that the description in the documentation is inaccurate as is pointed out in the comment:

The following statement regarding uncaught exceptions seems to be either inaccurate or misleading: 

"At run time, Flash Player ignores, by design, uncaught errors and tries to continue playing if the error doesn't stop the current SWF file"    

Script execution does NOT continue when hitting an error - even in a non-debug player.  Previous versions of AS/Flash Player used to continue.  For the non-debug Player, this is arguably a better approach as it prevents small errors from bringing down an entire block of script.

Our experience confirms this.  Is there any way to globally specify that the application should continue on uncaught errors?

We saw this class: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/fla sh/events/UncaughtErrorEvents...

It seems to be only available in 10.1 - which is higher than we would like to target.

Views

1.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 12, 2010 Nov 12, 2010

Copy link to clipboard

Copied

Here are the files:

http://www.theyrule.net/test/CS3.html (the code with the error is placed on the timeline)

http://www.theyrule.net/test/FB.html (The code with the error is wrapped in a simple class - see above)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Nov 15, 2010 Nov 15, 2010

Copy link to clipboard

Copied

In Flash Builder, try doing

if(this.hasOwnProperty("d") && this["d"] == 1){ }

If the flash player encounters an error in the constructor of the sprite/movieclip which is the main class, it will not be able to continue. If this error had occurred in an event handler, then you'd be able to continue.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 15, 2010 Nov 15, 2010

Copy link to clipboard

Copied

LATEST

Thanks Anirudh,

In Flash Builder, try doing

if(this.hasOwnProperty("d") && this["d"] == 1){ }

I was just throwing this error as an example of throwing an error, and not looking to fix it in particular.  We have a large and complex application which is used by many people.  Unfortunately, some of our users are experiencing runtime errors that are stopping the execution of the script - and we do not know exactly where those are.  They may be easy to fix once we can locate them. Unfortunately, we have not been able to reproduce them locally.

If the flash player encounters an error in the constructor of the sprite/movieclip which is the main class, it will not be able to continue. If this error had occurred in an event handler, then you'd be able to continue.

Can you tell us more about the rules of uncaught runtime error handling? For example: when I compile this code - the sprite is not shown on the stage and the second trace is not executed - despite having moved the code to an event handler function.

package

{

import flash.display.MovieClip;

import flash.display.Sprite;

import flash.events.Event;

import flash.events.TimerEvent;

import flash.utils.Timer;

import org.osmf.events.TimeEvent;

public class ErrorTest extends MovieClip

{

public function ErrorTest()

{

var t:Timer = new Timer(100, 1);

t.addEventListener(TimerEvent.TIMER, eventHandler);

t.start();

}

protected function eventHandler(e:Event):void {

trace("1");

if(this["d"] == 1){}

trace("2");

var s:Sprite = new Sprite();

s.graphics.beginFill(0xFFCC00);

s.graphics.drawRect(0,0,200,200);

addChild(s);

}

}

}

I'd like to publish our application such that it would ignore all run time errors. Are there any compiler or other options to achieve that.

Ideally we'd like to collate the errors such that end users could open a hidden text field and copy the error messages and send them to us.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines