Open up the Action Editor. Start the Flash program and select a new Actionscript 3.0 file from the opening screen that appears. Select Actions from the Windows menu on the main menu bar.
Code an instance of the object you are going to draw with the Sprite class. Name this instance shape1.
var shape1:Sprite = new Sprite();
Assign the lineStyle parameters for shape1 so its border has a width of 1 pixel, a line color of black, or 0, and a line opacity with no transparency, 1. Use the graphics.line style method to set these properties.
shape1.graphics.lineStyle(1, 0, 1);
Color the shape1 instance with yellow. Use the graphics beginFill method with the color code FFFF00 for yellow. Prefix the color code with 0x.
shape1.graphics.beginFill(0xFFFF00);
Create the circle with the drawCircle method. Center the circle at the stage coordinates x=200 and y=200. Set the circle's radius to 50.
shape1.graphics.drawCircle(200, 200, 50);
Place the completed circle, shape1, onto the flash stage. Use the addChild method.
addChild(shape1);
Create an event listener so that the circle will detect when the cursor is positioned over it and the mouse is clicked. Associate with the event listener a function name. Use the addEventListener method's MouseEvent.CLICK parameter. Name the function moveCircle.
shape1.addEventListener(MouseEvent.CLICK, moveCircle);
Code the moveCircle function such that the circle will move right 50 pixels every time the user clicks the circle with the mouse. Use the x position property of the Sprite class to move the circle. Set the function's return class type to void.
function moveCircle(event:MouseEvent): void
{
shape1.x =shape1.x + 50;
};
Examine the completed code. Review it for any potential typing errors or code errors. Compare what you typed in the editor to the code listing below.
var shape1:Sprite = new Sprite();
shape1.graphics.lineStyle(1, 0, 1);
shape1.graphics.beginFill(0xFFFF00);
shape1.graphics.drawCircle(200, 200, 50);
addChild(shape1);
shape1.addEventListener(MouseEvent.CLICK, moveCircle);
function moveCircle(event:MouseEvent): void
{
shape1.x =shape1.x + 50;
};
Select the check syntax icon, the icon with the check mark, located on the action editor's toolbar. Correct any and all errors that it reports. Consider that most errors are typing errors.
Select Test Movie from the Control menu on the main menu bar. Click the yellow circle that appears on the stage and verify that it moves when clicked with the mouse. Check to see if any compiler errors were generated in the Output box. Fix any errors that are generated.