18
INTRO TO ACTIONSCRIPT 3.0 The Bad News: Learning ActionScript is as Much Fun as Being Torn Apart By a Pack of Crazed Wombats. (And I say that in a loving way.) But you’ll be fine. I promise. The Good News: 90% of a designer’s code will consist of 5-10% of available ActionScript J. DAVIS

INTRO TO ACTIONSCRIPT 3.0 The Bad News: Learning ActionScript is as Much Fun as Being Torn Apart By a Pack of Crazed Wombats. (And I say that in a loving

Embed Size (px)

Citation preview

Page 1: INTRO TO ACTIONSCRIPT 3.0 The Bad News: Learning ActionScript is as Much Fun as Being Torn Apart By a Pack of Crazed Wombats. (And I say that in a loving

INTRO TO ACTIONSCRIPT 3.0

The Bad News:Learning ActionScript is as Much Fun as Being Torn Apart By a Pack of Crazed Wombats.

(And I say that in a loving way.)But you’ll be fine. I promise.

The Good News:90% of a designer’s code will consist of 5-10% of available ActionScript

J. DAVIS

Page 2: INTRO TO ACTIONSCRIPT 3.0 The Bad News: Learning ActionScript is as Much Fun as Being Torn Apart By a Pack of Crazed Wombats. (And I say that in a loving

You won’t ever be held responsible for a scripting problem in your work that you can’t figure out—as long as you contact me so I can troubleshoot with you.

You won’t have to memorize scripts just yet. You can just copy and paste them and change the parts you need to change, to learn how it works.

My Guarantee To You

Page 3: INTRO TO ACTIONSCRIPT 3.0 The Bad News: Learning ActionScript is as Much Fun as Being Torn Apart By a Pack of Crazed Wombats. (And I say that in a loving

Introduction

1) Programming Language vs. Scripting Language 2) Syntax vs. Semantics (how words are arranged in

sentences versus the linguistic meaning of words) 3) The computer is dumb. 4) ActionScripting is case sensitive 5) Camel case convention: John Doe becomes johnDoe 6) Spaces: ActionScript deletes them all when running

script. 7) Scripts are also called instructions or commands 8) “Runtime error” – script runs, but doesn’t do what

you want it to 9) Movie clips are “objects” (as are other things that can

be instructed). 10) ActionScript 3 can be created in the Flash authoring

environment, in a text editor, or in Flex.

Page 4: INTRO TO ACTIONSCRIPT 3.0 The Bad News: Learning ActionScript is as Much Fun as Being Torn Apart By a Pack of Crazed Wombats. (And I say that in a loving

The Actions Pane (Windows>Actions)

“Global” actionsappear on thefirst frame of amovie.

Page 5: INTRO TO ACTIONSCRIPT 3.0 The Bad News: Learning ActionScript is as Much Fun as Being Torn Apart By a Pack of Crazed Wombats. (And I say that in a loving

2 SYNTACTIC RULES OF ACTIONSCRIPTING

1) Use a semicolon at the end of each line

2) object.method (argument); like noun.verb (adjective);

Example 1root.gotoAndPlay(2);this.gotoAndPlay(2);gotoAndPlay(2);

Explanation: This script instructs the playhead on the main timeline (“root” or “this”) to go to and stop on frame 2. Identifying “root” or “this” by name is optional—the current timeline is the default, so you could just say gotoAndStop(2);

Page 6: INTRO TO ACTIONSCRIPT 3.0 The Bad News: Learning ActionScript is as Much Fun as Being Torn Apart By a Pack of Crazed Wombats. (And I say that in a loving

More Scripts

Example 2stop() ;play();movieclipinstance.play();

Explanation: Some instructions are implied.  

Example 2movieclipinstance.gotoAndStop(“musicoff”)

Explanation: This script instructs the playhead inside of a movieclip instance to go to and stop on a frame that has been labeled “musicoff.”

Page 7: INTRO TO ACTIONSCRIPT 3.0 The Bad News: Learning ActionScript is as Much Fun as Being Torn Apart By a Pack of Crazed Wombats. (And I say that in a loving

2 Most Common Uses of Scripts

Controlling a timeline example: stop();

Controlling a movieclipexample: moviclipinstancename.play(3);

Page 8: INTRO TO ACTIONSCRIPT 3.0 The Bad News: Learning ActionScript is as Much Fun as Being Torn Apart By a Pack of Crazed Wombats. (And I say that in a loving

2 Notes:

Indenting: Flash automatically indents lines of script so that they are visually scannable. Blocks are used for visual scannability as well as practical reasons.

// This signals commentary that is not script. //

Page 9: INTRO TO ACTIONSCRIPT 3.0 The Bad News: Learning ActionScript is as Much Fun as Being Torn Apart By a Pack of Crazed Wombats. (And I say that in a loving

Controling Time Lines

Main timelinegotoAndPlay(2) ORroot.gotoAndPlay(2) ORthis.gotoAndPlay(2)

A movieclip timeline (“child”)(the movieclip instance must be named and must be on stage)movieclipinstancename.gotoAndPlay(2)movieclipinstancename.gotoAndStop(2)

ORinstance1.instance2.gotoAndStop(2)[in the above case, instance1 is inside of instance2—example, control Godzilla’s breath]

A parent movieclip timelineparent.gotoAndPlay(2)parent.gotoAndStop(2)

Page 10: INTRO TO ACTIONSCRIPT 3.0 The Bad News: Learning ActionScript is as Much Fun as Being Torn Apart By a Pack of Crazed Wombats. (And I say that in a loving

Methods

To See All Movie Clip Methods:Flash.Display>Movie Clips>Methods

Popular Methods:stopplaygotoAndStopgotoAndPlayprevFramenextFramenavigateToURL

Page 11: INTRO TO ACTIONSCRIPT 3.0 The Bad News: Learning ActionScript is as Much Fun as Being Torn Apart By a Pack of Crazed Wombats. (And I say that in a loving

Buttons

Page 12: INTRO TO ACTIONSCRIPT 3.0 The Bad News: Learning ActionScript is as Much Fun as Being Torn Apart By a Pack of Crazed Wombats. (And I say that in a loving

Mouse Events

To See All Mouse Event PropertiesFlash.Events>MouseEvents>Properties>MOUSE_DOWN (and others)

Popular Mouse Event Properties:CLICKMOUSE_DOWNMOUSE_MOVEMOUSE_OUTMOUSE_OVERMOUSE_UPMOUSE_WHEELROLL_OUTROLL_OVER

Page 13: INTRO TO ACTIONSCRIPT 3.0 The Bad News: Learning ActionScript is as Much Fun as Being Torn Apart By a Pack of Crazed Wombats. (And I say that in a loving

Let’s Try It

Introduce Assignment:

TUTORIAL #1: Simple Exercise: Script Buttons to gotoAndStop on Frames

See finished file at: www.julietdavis.com/flashtutorials/simpleActionScriptExercise.fla www.julietdavis.com/flashtutorials/simpleActionScriptExercise.swf See next screen and Word doc: Intro to ActionScript 3.0

Page 14: INTRO TO ACTIONSCRIPT 3.0 The Bad News: Learning ActionScript is as Much Fun as Being Torn Apart By a Pack of Crazed Wombats. (And I say that in a loving
Page 15: INTRO TO ACTIONSCRIPT 3.0 The Bad News: Learning ActionScript is as Much Fun as Being Torn Apart By a Pack of Crazed Wombats. (And I say that in a loving

“Script THIS”

Name your instances FIRST (button instances)

stop();

btn1_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler1);function mouseDownHandler1(event:MouseEvent):void {    gotoAndStop (10); }

btn2_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler2);function mouseDownHandler2(event:MouseEvent):void {    gotoAndStop (1); }

Page 16: INTRO TO ACTIONSCRIPT 3.0 The Bad News: Learning ActionScript is as Much Fun as Being Torn Apart By a Pack of Crazed Wombats. (And I say that in a loving

Common Mistakes That Mess Up Scripts

1) Instance Name. First, make sure you have named the instance of your movie clip that you are applying the script to, and you have targeted that instance name and NOT the name of the movie clip that’s in the library.

2) Curly Brace. Make sure you have used a curly brace to end your block.

3) Function Names. In each set of instructions, the function name appears twice (think of them as twins)—make sure they are identical (e.g., mouseDownHandler1 and mouseDownHandler1). BUT, for each separate set of instructions, there must be separate sets of function names (e.g., mouseDownHandler2 and mouseDownHandler2. Example: See the scripts for the color picker.

4) SPELLING! Button instance names and movie clip instance names must be spelled exactly in the script as they have been named.

5) If all else fails, paste the scripts directly from the tutorial files and only change the parts in red.

Page 17: INTRO TO ACTIONSCRIPT 3.0 The Bad News: Learning ActionScript is as Much Fun as Being Torn Apart By a Pack of Crazed Wombats. (And I say that in a loving

Where to Find Script Assists

For Movie Clip Class:Flash.Display>Movie Clips>Methods

For Add Event Listener:Flash.Events>IEventDispatcherInterface>Methods>Add Event Listener

For Mouse Event Properties:Flash.Events>MouseEvents>Properties>MOUSE_DOWN

NOTE ABOUT SCRIPT ASSIST

Page 18: INTRO TO ACTIONSCRIPT 3.0 The Bad News: Learning ActionScript is as Much Fun as Being Torn Apart By a Pack of Crazed Wombats. (And I say that in a loving

QUESTIONS?