# Flash mx/8 animating flag tutorial



## aconite (Feb 1, 2006)

Hi,

Does anyone know where I might find a tutorial on how to animate a flag ?

thanks


----------



## knight_47 (Mar 15, 2006)

I don't know how, but this site has a bunch of animated flags. Gif format.

http://www.fg-a.com/flags.htm


----------



## knight_47 (Mar 15, 2006)

I found this, I'm sure it will help you get on the right track.

http://www.hesido.com/base.php?page=tutorials&sub=wavingflag


----------



## Sequal7 (Apr 15, 2001)

This will work with actionscripting....however, the registration point of the clip should be the top left corner.

```
/*** Link name of the clip ***/
clip="yourclipname";

/*** Constants ***/
startX=10;		// position of left hand of image
startY=10;		// position of left hand of image
amplitude=5;		// amplitude of oscillations
angleIncrement=1;	// speed of oscillations
periode=8;		// period of oscillations
clips=[];		// array that will contain the duplicated clips

/*** Functions 
	- init: initialize variables width and height
	- drawMask: draws a mask of given width and height
	- oscillate: makes a slice oscillate
	- splitImage: splits the image into a given amount of slices
***/
function init(){
	this.createEmptyMovieClip("container",0);
	container.attachMovie(clip,clip,0);
	container._x=startX;
	container._y=startY;
	width=container._width;
	height=container._height;
	container.removeMovieClip();
}
function drawMask(targ,width,height){
	var mask=targ.createEmptyMovieClip("mask",1);
	mask.beginFill(0,100);
	mask.lineTo(width,0);
	mask.lineTo(width,height);
	mask.lineTo(0,height);
	mask.endFill();
	return mask;
}
function oscillate(targ){
	targ._y=startY+amplitude*Math.sin(targ.angle/periode);
	targ.angle+=angleIncrement;
}
function splitImage(slices){
	var j=1;
	for (var i=0;i < slices;i++){
		clips.push(createEmptyMovieClip("container"+j,j++));
		clips[i].attachMovie(clip,clip,0);
		clips[i]._x=startX;
		clips[i]._y=startY;
		clips[i].angle=i;
		var index=width/slices;
		var mask=drawMask(clips[i],index,height);
		mask._x=i*index;
		mask._y=0;
		clips[i].setMask(mask);
		clips[i].onEnterFrame=function(){
//			a=this._name.substr(9);
//			this._y+= a%2 ? 1 : -1;
			oscillate(this);
		}
	}
}

/*** Run the functions ***/
init();
splitImage(30);
```
If your not sure how to add the actionscripting above, then you can look at this other example and perhaps it will assist you in rendering your flag.
http://www.senocular.com/flash/source.php?id=0.188


----------

