1 / 17

ActionScript

A Primer. ActionScript. ActionScript is…. Based on JavaScript Object-oriented programming Everything you do in ActionScript does something to some object* Some objects in Flash Movie Clip Graphic Button Objects are defined by classes in AS3.

vidor
Download Presentation

ActionScript

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. A Primer ActionScript

  2. ActionScript is… • Based on JavaScript • Object-oriented programming • Everything you do in ActionScript does something to some object* • Some objects in Flash • Movie Clip • Graphic • Button • Objects are defined by classes in AS3 *anything you can manipulate in some way

  3. ActionScript Deconstructed • Class: a group of items that are similar in some way • Items are called objects or instances of the class • Objects can be concrete (like a button or graphic) or abstract (like a variable that is invisible, but hold data) • Objects have two aspects: form (properties) and function (methods) • Each property and method is defined by Actions (pieces of code that tell Flash how to manipulate a target object at any point in your movie).

  4. ActionScriptMetaphor • Ball could be considered a class of items defined as “spherical things” • One object in this class is a movie clip called Tennis_ball • The properties of Tennis_ball might be the color neon green or a 20-pixel diameter • Its methods might be bounce, roll, and/or spin • A 2ndobject in the ball class might be Softball • Properties white…etc.

  5. Basic Programming Concepts &Constructs • syntax • variables • constants • statements • assignment statements • keywords • operators • expressions • arrays • procedures • functions • arguments • control structures • loops • conditions • comments

  6. What you can do with ActionScript? • control the playhead of a timeline • move things around • create and manage user interfaces • play sounds • control video • manage data (xml, lists, etc) • communicate with server-side applications (e.g., web servers)

  7. Actions window panel • select frame 1 • type the following into the Actions panel: • var message = "Hello world!"; • that line of code constitutes a complete instruction, known as a statement • now create three more statements: varfirstName = "your name here"; trace(message); trace ("Hi there, " + firstName + ", nice to meet you."); • play the movie - select Control>>Test Movie

  8. ActionScriptSyntax • ActionScript notation must end in ; • 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 play on frame 2. Identifying “root” or “this” by name is optional—the current timeline is the default, so you could just say gotoAndPlay(2);

  9. Write ActionScript in Flash • To write AS on Timeline: • Click on a key frame and then press F9.

  10. Timeline Script (for AS3.0) Methods: • play(); • stop(); • gotoAndPlay(); • gotoAndStop(); • nextFrame(); • prevFrame(); • navigateToURL(); Properties • currentFrame • currentLabel • currentLabels • totalFrames

  11. Using Symbols • Reusable content stored in Library • Create instance from symbols, and name

  12. Exercise • Make a pictures slideshow (SlideShow.fla)

  13. Solution (1) • Open a Flash file (AS3.0) • Import pics to library (File->Import) • Convert the pics to Movie Clip (Optional) • Make keyframes and place a pic to every Keyframe

  14. Solution (2) • Create a button symbol and put it in a new layer • Make two instances (next, prev) from the button symbol • Give an instance name “nextButton” and another one “previousButton”

  15. Solution (3) • Create a new layer and name it, say, “AS3” • Write code on the keyframe of the AS3 layer

  16. Solution (4) – Code AS3.0 • stop(); • nextButton.addEventListener(MouseEvent.CLICK, onNextButtonClicked); • previousButton.addEventListener(MouseEvent.CLICK, onPreviousButtonClicked); • functiononNextButtonClicked(e:MouseEvent):void { • if (currentFrame == totalFrames) { • gotoAndStop(1); • } else { • nextFrame(); • } • } • functiononPreviousButtonClicked(e:MouseEvent):void { • if (currentFrame == 1) { • gotoAndStop(totalFrames); • } else { • prevFrame(); • } • }

  17. Solution (4) – Code AS3.0 • stop(); • // add an event listener to the next button • nextButton.addEventListener(MouseEvent.CLICK, onNextButtonClicked); • // add an event listener to the previous button • previousButton.addEventListener(MouseEvent.CLICK, onPreviousButtonClicked); • // a function that goes to the next frame when the next button is clicked • functiononNextButtonClicked(e:MouseEvent):void { • if (currentFrame == totalFrames) { • gotoAndStop(1); • } else { • nextFrame(); • } • } • // a function that goes to the previous frame when the next button is clicked • functiononPreviousButtonClicked(e:MouseEvent):void { • if (currentFrame == 1) { • gotoAndStop(totalFrames); • } else { • prevFrame(); • } • }

More Related