OOPs: More Classes

Get Adobe Flash player
  1. Download the Flag.as class and save it in your project directory.
  2. Download the USFlag project and save it in the same directory.
The code for the Flag class is shown below:
package {
	import flash.display.*;
	import flash.geom.*;
	import flash.filters.*;
	import flash.events.*;
	public class Flag extends MovieClip {
   		 	var bm:BitmapData;
            var disp:DisplacementMapFilter;
            var pt1:Point = new Point(0,0);
            var pt2:Point = new Point(0,0);
            var perlinOffset:Array = [pt1, pt2];
			var v:Number = 0;
			var mySprite:Sprite = new Sprite();
           public function Flag() {//constructor
                bm=new BitmapData(this.width, this.height);
				disp=new DisplacementMapFilter(bm,new Point(0,0),1,2,10,60);
                addEventListener(Event.ENTER_FRAME, frames);
		   function frames(e:Event):void {
			   bm.perlinNoise(bm.width,bm.height,2,5,false,true,7,false,[new Point(v,0),new Point(v,0)]);
				this.filters = [new DisplacementMapFilter(bm,new Point(0,0),1,1,30,30,"color")];
				v += 10;
     } //class
} //package
You can use any picture of a flag.
Add a second layer and draw a rectangle that is bigger than the flag.
Make it a movie clip and then set its alpha value to 0.
This extra border around the flag is the area that gives it room to wave.

NEXT: OOPs: Creating a Bobber Class