Communication

Flash movies can communicate with each other and with the html page.
We will start with a ball the moves back and forth.

Get Adobe Flash playerStart a new movie and make a movie clip of a ball. Name the instance ball. Write the code as shown below:

var speed:int=1;
if("speed" in stage.loaderInfo.parameters) {
	speed=stage.loaderInfo.parameters["speed"];
}
this.addEventListener(Event.ENTER_FRAME,frames);
function frames(e:Event):void {
	ball.x+=speed;
	if(ball.x>stage.stageWidth-ball.width || ball.x<0)  {
	   speed*=-1;
	}
}//frames
The code says to look for a parameter on the html page called "speed" and assign it as the value for the variable speed.
At this point we haven't added parameters to the page and the the speed is 1.

Experiment: Download the movie

NEXT: Publish the movie