OOPs: More Classes

The class file must import any classes that it uses. Most classes will need the flash display and events:

package  {
	//imports
    import flash.display.*;
	import flash.events.*;

	public class Bubble extends MovieClip {
       //variables
       var dx:int=0;
       public var dy:int=-2;
       var origX:int;
       
	   public function Bubble() {
			// constructor code: anything that happens ONCE at the beginning
			addEventListener(Event.ENTER_FRAME,frames);
            origX=this.x;
		} //constructor
      //other functions
      function frames(event:Event):void {
	     dx=Math.random()*5; //0 to 4
	     dx-=2; //-2 to +2
	     this.x+=dx;
	     this.y+=dy;
	     if(this.y<0-this.height) {
		    this.y=stage.stageHeight+this.height;
		    this.x=origX;
	     }
       } //frames
	} //class
} //package

It is a good idea to save after each step because you are moving back and forth between the as file and the code in the original movie.

NEXT: Linkage