Thursday, July 22, 2010

Action Script 3 Set Location and Event Activity

*to view the HTML page click here

Set Location

In this exercise we set a location for the square.

Click Here to see what it looks like!

In this script we started by creating a shape. After creating this shape, we took the object and made it into a movie clip and saved it in our library. After saving it to the library, you then drag the movie clip into the stage where you then insert a script that sets the location. For this example the set location was inserted like this:



this.stop();
square.x=220;
square.y=200;
/* X and Y are there to position exactly where you want the image or shape to be. Also in the properties box for your image you must give it and instance name */

* this.stop(); is used to stop the entire movie to not move forward.

* square.x or .y are the coordinates you want to set for your movie clip. The first part shows what name you gave the object the .x or y tells you where the image would be located on the screen and the number represents the numerical location of the object.

* the rest is personal notes (or comments) you have taken to know what you have done in the past!

This script is a basic one that tell the shape the EXACT location it should be.

Event Activity in ActionScript

In this exercise we give the object a command to react.

Click Here to see what it looks like!

In this exercise we had to create and object that will react to a mouse over. I will break down what each section does and why.

ActionScript code:

this.stop();
*just as in the set location we start our script language with this.stop

blink.stop();//stops movie clip
*"blink.spot" does exactly that... stops the blink or stop's the movie clip from continuing.

blink.buttonMode=true;//property allows MC to have button cursor
*changes arrow to a finger.

blink.addEventListener(MouseEvent.CLICK, clickHandler);
*event listener is telling what blink is about to do. The mouse event is going to be "click"

function clickHandler(evt:MouseEvent):void {
trace("you have clicked on me");
if (evt.shiftKey == true) {
trace("you get to go to the secret gallery");
};
};
*the use of trace is used to make sure if you do or do not have any errors and will show in the output panel. the "if" statement is used to check if some one is holding down the shift key.

blink.addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
function mouseOverHandler(evt:MouseEvent):void {
blink.gotoAndStop(2);//inside MC, go back to blue
};


blink.addEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler);
function mouseOutHandler(evt:MouseEvent):void { (Void type was used as the parameter list in a function definition to indicate no parameters.)
blink.gotoAndStop(1);
};

*the second event listener is set for when the mouse is past the hot spot of where, for this example, the circle is located at and brings it back to the original color.

In all, this can be used in rollovers or a spry type of menu bar an various other function that can be useful in a flash file.

No comments:

Post a Comment