1 Flash Actionscript Actionscript and Objects. 2 Actionscript and Objects ActionScript is what's known as an object-oriented programming language. Object-oriented.

Slides:



Advertisements
Similar presentations
Introduction to Macromedia Director 8.5 – Lingo
Advertisements

INTRODUCTION TO ADOBE FLASH CS4
1What is the Stage. 2How do you open a panel in Flash
© 2010 Delmar, Cengage Learning Chapter 9: Using ActionScript.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 18 – Macromedia Flash MX 2004: Building an Interactive Game Outline 18.1 Introduction 18.2 Object-Oriented.
Modules and Objects Introduction to Computing Science and Programming I.
Macromedia Flash MX 2004 – Design Professional and Interactivity WORKING WITH SYMBOLS.
1 Flash Actionscript Event Handling. 2 Event Handling Right now we know all about variables lets go back to our text input/output example: Suppose we.
Flash Workshop Flash Workshop :: Agenda  Introductions  Look at a few Flash Examples  Flash Web Sites  Flash Web Applications  Flash Games.
Work with symbols and instances Work with Libraries Create buttons Assign actions to buttons Unit Lessons.
1 Flash Actionscript Adding Interactive Actions Variables.
Kapi’olani Community College Art 258 Interface Programming II In-class Presentation Week 5A.
Introduction to Macromedia Flash 8
1 Flash Programming Introduction Script Assist. 2 Course Description This course concentrates on the teaching of Actionscript, the programming language.
Creating Animation Pertemuan Matakuliah: L0182 / Web & Animation Design Tahun: 2008.
MovieClips & Properties Flash ActionScript Introduction to Thomas Lövgren
© 2011 Delmar, Cengage Learning Chapter 8 Building Complex Animations.
Chapter 9 Introduction to ActionScript 3.0. Chapter 9 Lessons 1.Understand ActionScript Work with instances of movie clip symbols 3.Use code snippets.
Chapter 3 Working with Symbols and Interactivity.
BUILDING RICH MEDIA ELEMENTS. Design Decisions Based on Design Specification  Following the design specification will ensure that the application is.
XP New Perspectives on Microsoft Office Access 2003 Tutorial 11 1 Microsoft Office Access 2003 Tutorial 11 – Using and Writing Visual Basic for Applications.
Lehigh University Introduction to Flash MX Sharmeen Mecklai.
Chapter 11 Adding Sound and Video. Chapter 11 Lessons 1.Work with sound 2.Specify synchronization options 3.Modify sounds 4.Use ActionScript with sound.
© 2011 Delmar, Cengage Learning Chapter 9 Introduction to ActionScript 3.0.
© The McGraw-Hill Companies, 2006 Chapter 4 Implementing methods.
© 2011 Delmar, Cengage Learning Chapter 3 Working with Symbols and Interactivity.
© 2012 Adobe Systems Incorporated. All Rights Reserved. Copyright 2012 Adobe Systems Incorporated. All rights reserved. ® INTRODUCTION TO FLASH ANIMATION.
® Copyright 2010 Adobe Systems Incorporated. All rights reserved. ® ® 1 INTRODUCTION TO ADOBE FLASH PROFESSIONAL CS5.
© 2010 Delmar, Cengage Learning Chapter 3: Working with Symbols and Interactivity.
Tutorial 8 Programming with ActionScript 3.0. XP Objectives Review the basics of ActionScript programming Compare ActionScript 2.0 and ActionScript 3.0.
CSC 361/661 Digital Media Spring 2010 Professor Burg.
Getting a handle on ActionScript A basic primer for non-programmers.
Creating Buttons – Lesson 71 Creating Buttons Lesson 7.
Adobe Flash CS3 Revealed Chapter 3 - WORKING WITH SYMBOLS AND INTERACTIVITY.
CSC 361/661 Digital Media Spring 2010 Professor Burg.
2006 Adobe Systems Incorporated. All Rights Reserved. 1 INTRODUCTION TO ADOBE FLASH CS3.
Term 2, 2011 Week 1. CONTENTS Problem-solving methodology Programming and scripting languages – Programming languages Programming languages – Scripting.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
Motion Tweening – Lesson 81 Motion Tweening Lesson 8.
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
Introduction to Flash Animation CS 318. Topics Introduction to Flash and animation The Flash development environment Creating Flash animations  Layers.
ActionScript: Addressing Display Objects, Duplicating MovieClips, Attaching MovieClips Dynamically MMP 220 Multimedia Programming This material was prepared.
Chapter 4 Introduction to Classes, Objects, Methods and strings
Chapter 2: Variables, Functions, Objects, and Events JavaScript - Introductory.
XP Tutorial 8 Adding Interactivity with ActionScript.
Variables, Scope, Images, Sound IM ActionScript.
Scripting and Interactivity 이병희
Macromedia Flash 8 Revealed WORKING WITH SYMBOLS AND INTERACTIVITY.
Macromedia Flash Design Professional And Interactivity WORKING WITH SYMBOLS.
© 2011 Delmar, Cengage Learning Chapter 10 Using ActionScript to Enhance User Experience.
Computer Game Design ActionScript is… Object-oriented programming Everything you do in ActionScript does something to some object* Some objects.
SCRIPT PROGRAMMING WITH FLASH Introductory Level 1.
Video in Macromedia Flash (Optional) – Lesson 121 Video in Macromedia Flash (Optional) Lesson 12.
Open a new Flash File Action Script 2.0. Create a button like you did last lesson and name it Click to Play.
Debugging tools in Flash CIS 126. Debugging Flash provides several tools for testing ActionScript in your SWF files. –The Debugger, lets you find errors.
XP Tutorial 3 Creating Animations. XP New Perspectives on Macromedia Flash MX Elements of Animation Layers are used to organize the content of.
Intro to ActionScript CIS 126 Greg Shorts. What Is ActionScript? ActionScript is the scripting language Flash uses to control its movies and the objects.
XP Tutorial 8 Adding Interactivity with ActionScript.
1.1: Objects and Classes msklug.weebly.com. Agenda: Attendance Let’s get started What is Java? Work Time.
DM 11- Flash –Unit C and Interactivity WORKING WITH SYMBOLS.
AD 305 Electronic Visualization I : School of Art and Design : University of Illinois at Chicago : Spring 2007 Intro to Action Script "The games of a people.
 Movieclip symbols are reusable pieces of flash animation  consisting usually of one or more graphic/button symbols  thus they are flash movies within.
var variableName:datatype;
Flash Interface, Commands and Functions
Unit Lessons Work with actions
Learning Objective LO: We’re learning to understand when it is appropriate to use particular data types.
INTRODUCTION TO ADOBE FLASH CS4
Interface Programming 2 Week 1
INTRODUCTION TO FLASH ANIMATION
Working with Symbols and Interactivity
Presentation transcript:

1 Flash Actionscript Actionscript and Objects

2 Actionscript and Objects ActionScript is what's known as an object-oriented programming language. Object-oriented programming is simply an approach to programming - really nothing more than a way to organize the code in a program, using objects. A computer program is often defined as a series of steps or instructions that the computer performs. Conceptually, then, we might imagine a computer program as just a single long list of instructions.

3 Actionscript and Objects However, in object-oriented programming, the program instructions are divided among different objects - the code is grouped into chunks of functionality, so related types of functionality or related pieces of information are grouped together in one container.

4 Actionscript and Objects In fact, because we’ve worked with symbols in Flash, we’re already used to working with objects. Imagine you've defined a movie clip symbol (e.g. a drawing of a rectangle) and you've placed a copy of it on the Stage. That movie clip symbol is also (literally) an object in ActionScript; it's an instance of the MovieClip class.

5 Actionscript and Objects There are various characteristics of the movie clip that you can modify. E.g, there are values you can change in the Property inspector, like its x coordinate, or its width, or various colour adjustments like changing its alpha (transparency), or applying a drop-shadow filter to it. All of these things that you can do to modify a movie clip symbol are also things you can do in ActionScript by changing the pieces of data that are all put together into a single bundle called a MovieClip object.

6 Actionscript and Objects In ActionScript object-oriented programming, there are three types of characteristics that any class can include: Properties Methods Events Together, these elements are used to manage the pieces of data used by the program and to decide what actions are carried out and in what order.

7 Properties A property represents one of the pieces of data that are bundled together in an object. A song object might have properties named artist and title; the MovieClip class has properties like rotation, x, width, and alpha. You work with properties like individual variables--in fact, you might think of properties as simply the "child" variables contained in an object.

8 Properties - Examples This moves the MovieClip named square to the x coordinate 100 pixels: square.x = 100; Uses the rotation property to make the square MovieClip rotate to match the rotation of the triangle MovieClip: square.rotation = triangle.rotation; Alters the horizontal scale of the square MovieClip so that it's one-and-a-half times wider than it used to be: square.scaleX = 1.5;

9 Properties Notice the common structure: you use a variable ( square, triangle ) as the name of the object, followed by a full stop (.) and then the name of the property ( x, rotation, scaleX ). The full stop, known as the dot operator, is used to indicate that you're accessing one of the child elements of an object. The whole structure together, "variable name-dot- property name," is used like a single variable, as a name for a single value in the computer's memory.

10 Methods A method is an action that can be performed by an object. E.g., if you've made a movie clip symbol in Flash with several keyframes and animation on its timeline, that movie clip can play, or stop, or be instructed to move the playhead to a particular frame.

11 Methods - Examples Instructs the MovieClip named shortFilm to start playing: shortFilm.play(); Makes the MovieClip named shortFilm stop playing (the playhead stops in place, like pausing a video): shortFilm.stop(); Makes the MovieClip named shortFilm move its playhead to Frame 1 and stop playing (like rewinding a video): shortFilm.gotoAndStop(1);

12 Methods Methods are accessed by writing the object's name (a variable), then a full stop, and then the name of the method followed by parentheses. The parentheses are the way that you indicate that you're calling the method--or in other words, instructing the object to perform that action.

13 Methods Sometimes values (or variables) are placed in the parentheses, as a way to pass along additional information that is needed to carry out the action. These values are known as method parameters. E.g., the gotoAndStop() method needs to know which frame it should go to, so it requires a single parameter in the parentheses – e.g. gotoAndStop(24). Other methods, like play() and stop(), are self-explanatory, so they don't require extra information. Nevertheless, they are still written with parentheses.

14 Methods Unlike properties (and variables), methods aren't used as value placeholders. However, some methods can perform calculations and return a result that can be used like a variable. E.g., the Number class's toString() method converts the numeric value to its text representation: var numericData:Number = 9; var textData:String = numericData.toString();

15 Methods For instance, you would use the toString() method if you wanted to display the value of a Number variable in a text field on the screen. The TextField class's text property (which represents the actual text content displayed on the screen) is defined as a String, so it can contain only text values. This code converts the numeric value in the variable numericData to text, and then makes it appear on the screen in the TextField object calculatorDisplay : calculatorDisplay.text = numericData.toString();

16 Events We've described a computer program as a series of instructions that the computer carries out step-by-step. Some simple computer programs consist of nothing more than that--a few steps which the computer carries out, at which point the program ends. However, ActionScript programs are designed to keep running, waiting for user input or other things to happen. Events are the mechanism that determines which instructions the computer carries out and when.

17 Events In essence, events are things that happen that ActionScript is aware of and can respond to. Many events are related to user interaction--like a user clicking a button, or pressing a key on the keyboard-- but there are also other types of events. E.g., if you use ActionScript to load an external image, there is an event that can let you know when the image has finished loading. In essence, when an ActionScript program is running, Adobe Flash Player just sits and waits for certain things to happen, and when those things happen, it runs the specific ActionScript code that you've specified for those events.

18 Creating Object Instances Before you can use an object in ActionScript, the object has to exist in the first place. One part of creating an object is declaring a variable; however, declaring a variable only creates an empty place in the computer's memory. You must assign an actual value to the variable--that is, create an object and store it in the variable--before you attempt to use or manipulate it. The process of creating an object is known as instantiating the object--in other words, creating an instance of a particular class.

19 Creating Object Instances One simple way to create an object instance doesn't involve ActionScript at all. In Flash, when you place a movie clip symbol, button symbol, or text field on the Stage, and you assign it an instance name in the Property inspector, Flash automatically declares a variable with that instance name, creates an object instance, and stores that object in the variable.

20 Creating Object Instances However, you won't always want to create an object visually. There are also several ways you can create object instances using only ActionScript. First, with several ActionScript data types, you can create an instance using a literal expression--a value written directly into the ActionScript code.

21 Creating Object Instances Literal numeric value (enter the number directly): var someNumber:Number = ; var someNegativeInteger:int = -53; var someUint:uint = 22; Literal String value (surround the text with double quotation marks): var firstName:String = "George"; var soliloquy:String = "To be or not to be, that is the question..."; Literal Boolean value (use the literal values true or false ): var niceWeather:Boolean = true; var playingOutside:Boolean = false;

22 Creating Object Instances For any other data type, to create an object instance you use the new operator with the class name, like this: var raceCar:MovieClip = new MovieClip(); var birthday:Date = new Date(2006, 7, 9); Creating an object using the new operator is often referred to as "calling the class's constructor." A constructor is a special method that is called as part of the process of creating an instance of a class. Notice that when you create an instance in this way, you put parentheses after the class name, and sometimes you specify parameter values--two things that you also do when calling a method.

23 Creating Object Instances NOTE: Even for those data types that let you create instances using a literal expression, you can still use the new operator to create an object instance. E.g., these two lines of code do exactly the same thing: var someNumber:Number = 6.33; var someNumber:Number = new Number(6.33);

24 Creating Object Instances It's important to be familiar with the new ClassName() way of creating objects. If you need to create an instance of any ActionScript data type that doesn't have a visual representation (and hence can't be created by placing an item on the Flash Stage), you can do so by creating the object directly in ActionScript using the new operator. The new operator can also be used to create an instance of a movie clip symbol that is defined in the Library but isn't placed on the Stage.

25 Actionscript and Objects Objects lie at the heart of the ActionScript 3.0 language - they are its fundamental building blocks. Every variable you declare, every function you write, and every class instance you create is an object. You can think of an ActionScript 3.0 program as a group of objects that carry out tasks, respond to events, and communicate with one another.