Using DataTyping

 <  Day Day Up  >  

In order for error handling to work in ActionScript 2.0, it is essential that we specify the data type (or the class) of all Objects, including visual Objects, at the beginning of the class file or at the top of the timeline code:

 var myArray :Array = new Array(); var myObject :Object = new Object(); var myColor :Color = new Color(); var myCombo :mx.control.ComboBox; var myMovieClip :MovieClip; 

It is also important to specify what type of data a function returns:

 function getArray () :Array {     return myArray; } 

Specifying a data type causes ActionScript 2.0 to perform type checking and display detailed error messages to the developer which greatly helps with debugging.

If a function does not return any data, we should type that function as Void :

 function setArray (passedArray :Array) :Void {     this.myArray = passedArray; } 


ActionScript 2.0 will allow you to declare an Object or Function without specifying a data type. However, before compiling your code, in order to receive the most verbose error messages possible, it is a best practice to make sure that all Objects and Functions have a data type specified. This will go a long way to making the debugging process easier.

 <  Day Day Up  >  

Object-Oriented Programming with ActionScript 2.0
Object-Oriented Programming with ActionScript 2.0
ISBN: 0735713804
EAN: 2147483647
Year: 2004
Pages: 162 © 2008-2017.
If you may any questions please contact us: