Sunday, November 7, 2010

Flash - ActionScript - Event Handling - Create a Listener - Create and Specify a Function

The first step in event handling is to create a listener that will detect the event.

A listener looks something like this:

wheretolisten.addEventListener(whatevent, responsetoevent);



The actual command is addEventListener().
wheretolisten is the object where the event occurs (usually a button). [e.g. "btn1" (a button that you named btn1)]
whatevent is the specific kind of event (such as a mouse click).  [e.g. "MouseEvent.CLICK" ]
respondtoevent is the name of a function that is triggered when the event happens. [e.g. "showimage1" (a function that you naemed showimage1)]




The next step is to create a function that will respond to the event.

A function is simple a group of actions that are bunched together. You can trigger a function be referencing its name.

A function looks something like this:

function showimage1 (myEvent: MouseEvent) {};

In the above example, the function receives one parameter (within the parentheses) called myEvent, which is an event that involes the mouse. The item following the colon indicates what type of object it is. If the function is triggered, all the actions between the curly brackets are executed.


**reference: "Adobe cs5 Flash Classroom in a Book"

Flash - ActionScript - Events / Event Listeners / Event Handlers

Some events are created by the user, for example a mouse click, a mouse movement, or a key press on the keyboard. Other events can happen inpedendent of the user, for example the successful loading of a piece of data, or the completion of a sound.

With Action Script you can write code that detects events and respond to them with an event handler.


*reference: "Adobe cs5 Flash Classroom in a Book"

Flash - ActionScript - Script Navigator

At the bottpm left of the Actions panel is the Script Navigator. The Script navigator can help you find a particular piece of code.

ActionScript is placed on keyframes on the Timeline, so the Script navigator can be particularly useful if you have lots of code scattered in different keyframes and on different Timelines.



**excerpted from "Flash CS5 Classroom in a Book"

Flash - ActionScript

ActionScript is placed on keyframes on the Timeline.

Flash - ActionScript - the Actions Panel

The Actions Panel is where you write all your code.

Ways to open the actions panel:
1. Windows -> Actions
2. select a keyframe on the timeline and click the "ActionScript icon" on the top right of the Properties inspector.
3. right-click/ctrl-click on any keyframe and select Actions.
4. select keyframe on the timeline and press "F9"

Flash - ActionScript - automatic help from flash tools

@ color codes:
+ words that have specific meanings in ActionScript, such as keywords and statements, appear in blue as you type them in the Actions panel.
+words that are not reserved in ActionScript, such as variable names, are in black.
+Strings appear in green.
+Comments (which are ignored by ActionScript), appear in gray.

@click the "check syntax icon" to make the tool check the syntax of your script

@click the "auto format icon" to format the script according to conventions, so that your script will be easier to read

**reference: "flash cs5 classroom in a book"

Flash - ActionScript - Syntax

scripting syntax

* the dot operator (.) provides a way to access the properties and methods of an object. Type the instance name, followed by a dot, and then the name of the property or method. Think of the dot as a way to separate objects, methods and properties.

* whenever you are entering a string or the name of a file, use quotation marks

--reference: "adobe cs5 flash classroom in a book"