Sunday, November 7, 2010

Flash - ActionScript - Using Labels on Keyframes

Your actionScript code tells flash to go to a different frame number when the user clicks each of the buttons. However, if you decide to edit your Timeline and add or delete a few frames, you will need to go back into your ActionScript and change your code so the frame numbers match.

An easy way to avoid this problem is to use frame labels instead of fixed frame numbers. Frame labels are names that you give to keyframes. Instead of referring to keyframes by their frame number, you refer to them by their label. So, even if you move your destination keyframes as you edit, the labels remain with their keyframes.

To reference frame labels in ActionScript, you must enclode them in quotation marks.

The command gotoAndStop("label1") makes the playhead go to the keyframe with the label called label1.

(to label a frame: in the Proerties inspector, enter label1 in the Label Name field.)

** excerpted from "Adobe Flash cs5 Classroom in a Book" **

Flash - ActionScript - ActionScript Commands for Navigation

ActionScript codes for common navigation commands.

Use these codes when you create buttons to stop the playhead, start the playhead, or move the playhead to different frames.

(note: the gotoAndStop and gotoAndPlay commands require additional information, or parameters, within their parentheses, as indicated)

*stop();
*play();
*gotoAndStop(framenumber or "framelabel");
*gotoAndPlay(framenumber or "framelabel");
*nextframe();
*prevframe();


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

Flash - ActionScript - Mouse Events

ActionScript codes for common mouse events.
(use these codes when you create ou listener)

*MouseEvent.CLICK
*MouseEvent.MOUSE_MOVE
*MouseEvent.MOUSE_DOWN
*MouseEvent.MOUSE_UP
*MouseEvent.MOUSE_OVER
*MouseEvent.MOUSE_OUT

Flash - ActionScript - adding the event listener and function

Add ActionScript code to listen for a mouse click on each button.

The response will make Flash fo to a particular frame on the Timeline to show different content.

(the above is referring specifically to the hand-on follow-along example on chapter 6 of "classroom in a book)

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"