flash language_api_execution_errors
Execution errors
We previously looked at compilation errors using the precise mode and touched on execution errors
One of the major new things in Flash player 9 is error management. As discussed, previous versions of Flash player didn’t show any execution errors and would fail in silence. When the execution of a program is abnormally stopped in ActionScript 3 we get an execution error alert. In order to generate an execution error we can test the following code:
// definition of a MovieClip type variable // its value by default is invalid var myClip:MovieClip; // we try to recuperate the number of images of the timeline’s clip // if the value is invalid an execution error is raised var nbImages:int = myClip.totalFrames;
The output panel displays the following error:
TypeError: Error #1009: It is impossible to access the property or method of an invalid object reference.
In order to generate this error, we can use the try catch block:
// definition of a MovieClip type variable // its value by default is invalid var myClip:MovieClip; var nbImages:int; // thanks to the try catch block we can generate the try error { nbImages = myClip.totalFrames; } catch ( pError:Error ) { trace ( "an execution error was raised!"); }
Of course we don’t systematically use the try catch blocks in order to avoid execution errors displaying. Certain simple tests, which we will discuss in these articles, will allow us to avoid having to resort to these blocks. In an execution error context it is advisable to define the two versions of the existing Flash player:
- Debugging version (Player Debug): this version of the player is made for development and execution error display by opening a window showing the current error. The player is automatically installed in the development environment of Flash CS3 or Flex Builder 2 and 3.
- Production version (Player Release): this version of the player is available from Adobe’s site. People that don’t have a development environment use this version of the player. This player doesn’t show execution errors so that it doesn’t interrupt the user experience.
With the debug player, the errors that aren’t generated by the try Catch block open the browser error panel as in the following image:
When an error is raised, the execution code is paused. We can therefore decide to continue the execution even though an error has just been raised or to totally stop the application’s execution.
Worth remembering
- The Flash 9 player raises execution errors.
- With the debug player these errors open a window showing the error in your browser.
- All of the ActionScript player’s API methods can raise execution errors.
- Flash player 9 no longer fails in silence, the debugging is therefore made easier.
Mediabox Training Centre © 2000 - 2008 All rights reserved.
Adobe Authorized Training Centre. State convention under number 25 14 02167 14.
Mediabox : SARL au capital de 62.000€ - Activity number: 25 14 02167 14 - SIRET : 493 716 468 00027
MEDIABOX, 102 Avenue des Champs Elysées, 75008 PARIS - Tel. +33(0)2.31.91.96.89 - Fax. +33(0)2.72.68.56.42



