The beauty of custom classes is that once you write a class, you can easily create as many instances of the class as you want in your application. In the applet below, we create two instances of the TriangleBoard class. The simple code placed on the MainTimeline that creates two instances is given below.
Download
- Download all files related to this tutorial in one zip file: as3_class_intro.zip
The fla file for the applet in the zipped package is as3_class_intro_4.fla. Again, you have to put the fla file and TriangleBoard.as in the same directory for the fla file to find the class.
The Code
Below is the complete code that we placed on the MainTimeline of as3_class_intro_4.fla:
var board1:TriangleBoard = new TriangleBoard(250,300);
this.addChild(board1);
board1.x = 15;
board1.y = 10;
var board2:TriangleBoard = new TriangleBoard(250,300);
this.addChild(board2);
board2.x = 285;
board2.y = 10;
//The RESET button clears both boards.
btnReset.addEventListener(MouseEvent.CLICK, resetAll);
function resetAll(e:MouseEvent):void {
board1.resetBoard();
board2.resetBoard();
}
As you see, there are great advantages to using AS3 classes!






