a primer n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
ActionScript PowerPoint Presentation
Download Presentation
ActionScript

Loading in 2 Seconds...

play fullscreen
1 / 37

ActionScript - PowerPoint PPT Presentation


  • 145 Views
  • Uploaded on

A Primer. ActionScript. ActionScript is…. Object-oriented programming Everything you do in ActionScript does something to some object* Some objects are called Symbols in Flash Movie Clip Graphic Button. * anything you can manipulate in some way. Object oriented?.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'ActionScript' - koleyna


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
actionscript is
ActionScript is…
  • Object-oriented programming
  • Everything you do in ActionScript does something to some object*
  • Some objects are called Symbols in Flash
    • Movie Clip
    • Graphic
    • Button

*anything you can manipulate in some way

object oriented
Object oriented?
  • You can decide what happens when a user clicks a button without worrying about how the button (or program) knows that it has been clicked
  • You can decide what changes to make to an object’s properties without knowing the internal mechanics of how those changes were made
  • You can program tasks incrementally without sitting down and writing the whole program from start to finish in one session
actionscript deconstructed
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).
actionscript metaphor
ActionScript Metaphor
  • 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.
actionscript flow
ActionScript Flow
  • Flash executes ActionScript statements starting with the first statement and continuing in order until it reaches the final statement or a statement that instructs ActionScript to go somewhere else.
slide7
One type of action that sends ActionScript somewhere other than the next statement is an if statement
actions
Actions
  • Tell Flash to do something
    • Frame actions
    • Object actions
  • Actions also can have parameters
gotoandplay
gotoAndPlay
  • This frame action sends the playhead to the specified frame in a scene and plays from that frame. If no scene is specified, the playhead goes to the specified frame in the current scene.
functions
Functions
  • Perform a specific task
  • Like in a spreadsheet program (Excel)
getversion
getVersion
  • Returns the Flash Player version number and operating system information.
  • You can use this function to determine whether the Flash Player that is in use can handle your Actionscript.
properties
Properties
  • All available information about an object
  • You can use ActionScript to read and modify object properties
  • All property names begin with an underscore (e.g., _visible)
visible false
_visible = false
  • This property make an object invisible
  • Assign the following action to a button…

On (release) {

_visible = false;

}

  • Button disappears on mouse click
method
Method
  • Similar to actions in that they effect objects
  • Built into objects
  • Invoked (Executed) through dot notation
rocketmc gotoandplay blastoff
RocketMC.gotoAndPlay(“BlastOff”);
  • ActionScript notation must end in ;
  • Movie clip Rocket MC goes to a frame labeled BlastOff and plays
variables
Variables
  • hold data for use in your Flash movies
  • Variables can hold any type of data
  • You could store:
    • User name
    • Result of calculation
    • True or false value
expressions
Expressions
  • An expression is any statement that Flash can evaluate and that returns a value.
  • You can create an expression by combining operators and values or by calling a function.
operators
Operators
  • Expressions use operators to tell Flash how to manipulate the values in the expression.
  • They are the commands that say “add these values” or “multiply these numbers”
some types of operators
Some types of operators
  • Assignment:
      • are used to assign values to variables.
      • The most common is (=). It makes the variable on the left equal to the value of the variable or expression on the right.
  • Comparison and equivalence:
      • (<), (>), (< =)
  • Numeric:
      • perform mathematical operations on values
looping
Looping
  • When you need to repeat certain actions in your movies more than once.
  • Makes coding more efficient, using the same set of commands as many times as necessary to complete a task.
looping examples
Looping examples
  • while
      • Creates a loop that continues to repeat as long as a condition remains true
  • for
      • Creates a loop that executes a specific number of times using a counter
  • for…in
      • Creates a loop that executes once for each member of a group of objects (class)
      • This makes certain that the entire group of objects is processed in the same way
hints
Hints
  • Before you begin writing scripts, formulate your goal and understand what you want to achieve.
  • Planning your scripts is as important as developing storyboards for your work.
  • Start by writing out what you want to happen in the movie, as in this example:
    • I want to create my whole site using Flash.
    • Site visitors will be asked for their name, which will be reused in messages throughout the site.
    • The site will have a draggable navigation bar with buttons that link to each section of the site.
    • When a navigation button is clicked, the new section will fade in at the center of the Stage.
    • One scene will have a contact form with the user's name already filled in.
write actionscript in flash
Write ActionScript in Flash
  • To write AS on Timeline:
    • Click on a key frame and then press F9.
timeline script for as3 0
Timeline Script (for AS3.0)

Methods:

  • play();
  • stop();
  • gotoAndPlay();
  • gotoAndStop();
  • nextFrame();
  • prevFrame();

Properties

  • currentFrame
  • currentLabel
  • currentLabels
  • totalFrames
accessing created symbol instances 1
Accessing Created Symbol Instances (1)
  • Create a symbol: MovieClip or SimpleButton.
  • Create an instance by dragging it from the library to the stage.
  • Input a name to every instance, say, movie1 and button1. After that, you can call these names in the AS.
  • Click on a keyframe and write code:
accessing created symbol instances 2
Accessing Created Symbol Instances (2)
  • Properties:

movie1.x = 20; //set x location

movie1.y = 40; // set y location

movie1.width = 100; // set new width

movie1.height = 200; // set new height

accessing created symbol instances 3
Accessing Created Symbol Instances (3)

Where these properties came from?

  • In AS3, all display objects are inherited from DisplayObject class.
  • movie1 is also DisplayObject so it can use every properties and methods of DisplayObject class.
  • For more details, click Help menu ->

-> ActionScript 3.0 Language and Component Reference

-> All Classes

-> DisplayObject

new event handling in as3 1

.addEventListener()

New Event Handling in AS3 (1)
  • AS3 changes the event handling, eg. Click on buttons, to a new mechanism.
    • on ()
    • onClipEvent()
    • .onload
    • addListener()
    • UIEventDispatcher()
new event handling in as3 2
New Event Handling in AS3 (2)

How to make a button clickable?

  • Create a symbol: Movie Clip or Button.
  • Create an instance by dragging it from the library to the stage.
  • Input a name to every instance, say, movie1 and button1.
  • Click on a keyframe and write code:

(Note in AS3, we can never write codes on buttons anymore. We MUST write these on the keyframe.)

new event handling in as3 21
New Event Handling in AS3 (2)
  • Full Syntax:

instanceName.addEventListener(type, listener, useCapture, priority, useWeakReference)

  • Minimized Syntax:

instanceName.addEventListener(type,listener);

  • Example:

playButton.addEventListener(MouseEvent.CLICK, onPlayButtonClick);

new event handling in as3 3
New Event Handling in AS3 (3)

button1.addEventListener(MouseEvent.CLICK, onButton1Click);

function onButton1Click(e:MouseEvent):void{

trace("button 1 Clicked");

}

movie1.addEventListener(MouseEvent.CLICK, onMovie1Click);

function onMovie1Click(e:MouseEvent):void{

trace("Movie 1 Clicked");

}

exercise
Exercise
  • Make a pictures slideshow (SlideShow.fla)
solution 1
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
solution 2
Solution (2)
  • Create a button symbol and put it in a new layer
  • Make 2 instances (next, prev) from the button symbol
  • Give an instance name “nextButton” and another one “previousButton”
solution 3
Solution (3)
  • Create a new layer and name it, say, “AS3”
  • Write code the keyframe of the AS3 layer
solution 4 code as3 0
Solution (4) – Code AS3.0
  • stop();
  • nextButton.addEventListener(MouseEvent.CLICK, onNextButtonClicked);
  • previousButton.addEventListener(MouseEvent.CLICK, onPreviousButtonClicked);
  • function onNextButtonClicked(e:MouseEvent):void {
  • if (currentFrame == totalFrames) {
  • gotoAndStop(1);
  • } else {
  • nextFrame();
  • }
  • }
  • function onPreviousButtonClicked(e:MouseEvent):void {
  • if (currentFrame == 1) {
  • gotoAndStop(totalFrames);
  • } else {
  • prevFrame();
  • }
  • }
solution 4 code as3 01
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
  • function onNextButtonClicked(e:MouseEvent):void {
  • if (currentFrame == totalFrames) {
  • gotoAndStop(1);
  • } else {
  • nextFrame();
  • }
  • }
  • // a function that goes to the previous frame when the next button is clicked
  • function onPreviousButtonClicked(e:MouseEvent):void {
  • if (currentFrame == 1) {
  • gotoAndStop(totalFrames);
  • } else {
  • prevFrame();
  • }
  • }