1 Flash Actionscript Adding Interactive Actions Variables.

Slides:



Advertisements
Similar presentations
© 2010 Delmar, Cengage Learning Chapter 9: Using ActionScript.
Advertisements

 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.
Introducing ActionScript 3.0 Object-oriented programming language Used to power Flash Player Similar to JavaScript Can be embedded in a Flash project.
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.
1 Flash Actionscript Animation. 2 Introduction to Sprites We will now look at implementing Sprites in Flash. We should know enough after this to create.
Work with symbols and instances Work with Libraries Create buttons Assign actions to buttons Unit Lessons.
Kapi’olani Community College Art 258 Interface Programming II In-class Presentation Week 5A.
Introduction to Macromedia Flash 8
1 Flash Actionscript Actionscript and Objects. 2 Actionscript and Objects ActionScript is what's known as an object-oriented programming language. Object-oriented.
1 Flash Actionscript Adding Interactive Actions. 2 ActionScript 3.0 ActionScript is the language you use to add interactivity to Flash applications, whether.
1 Flash Programming Introduction Script Assist. 2 Course Description This course concentrates on the teaching of Actionscript, the programming language.
Roentgen photo effect. This detailed, thoroughly explained lesson will show you how to create very attractive roentgen photo effect. You can use this.
© 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.
Frame Part of timeline panel You can remove normal frames from a certain layer by (MRC + Remove Frames). You can remove normal frames from a certain layer.
Chapter 3 Working with Symbols and Interactivity.
XP Tutorial 5 Buttons, Behaviors, and Sounds. XP New Perspectives on Macromedia Flash MX Buttons Interactive means that the user has some level.
Introduction to Flash FYS100 Creative Discovery in Digital Art Forms Spring 2007 Burg.
Flash MX II. Flash MX – Tweened Animation There are two methods for creating an animation sequence in Flash –Frame-by-frame animation –Tweened animation.
Lehigh University Introduction to Flash MX Sharmeen Mecklai.
Tutorial 5 Making a Document Interactive. XP Objectives Explore the different button states Add a button from the Button library Create a button Learn.
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.
06/10/ Working with Data. 206/10/2015 Learning Objectives Explain the circumstances when the following might be useful: Disabling buttons and.
© 2011 Delmar, Cengage Learning Chapter 3 Working with Symbols and Interactivity.
© 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.
Programming games Flash drawing trick(s). Past due: Your completion of rock-paper-scissors) Classwork: Bouncing ball: read tutorial. Start coding.
Programming games Show your version of Bo the dog. Start cannonball Preview: video, audio work session (cannonball) Homework: Cannonball with ball in a.
XP Tutorial 4 Special Animations. XP New Perspectives on Macromedia Flash MX Special Layers for Animation Animation Using a Motion Guide Layer.
Adobe Flash CS3 Revealed Chapter 3 - WORKING WITH SYMBOLS AND INTERACTIVITY.
More Tips on Flash CSC361/661 Digital Media Spring 2007 Burg.
CSC 361/661 Digital Media Spring 2010 Professor Burg.
Looping and Counting Lecture 3 Hartmut Kaiser
Distributed Multimedia Programming Week – 4A Buttons Movie Clips.
XP Tutorial 8 Adding Interactivity with ActionScript.
Variables, Scope, Images, Sound IM ActionScript.
Building the Events Components– Lesson 111 Building the Events Components Lesson 11.
Introduction to Flash CSC361/661 Digital Media Spring 2007 Burg.
Macromedia Flash 8 Revealed WORKING WITH SYMBOLS AND INTERACTIVITY.
Macromedia Flash Design Professional And Interactivity WORKING WITH SYMBOLS.
Distributed Multimedia Programming Week - 6 ActionScripts Basics and Behaviors Working with Text.
© 2011 Delmar, Cengage Learning Chapter 10 Using ActionScript to Enhance User Experience.
SCRIPT PROGRAMMING WITH FLASH Introductory Level 1.
Video in Macromedia Flash (Optional) – Lesson 121 Video in Macromedia Flash (Optional) Lesson 12.
PROGRAMMING IN PYTHON LETS LEARN SOME CODE TOGETHER!
FLASH!!!!!!!!!!!!!!!!!!!!!!!!! A TUTORIAL BY BRITTANY HESS AND MARGARET DENTON.
CIS 205—Web Design & Development Flash Chapter 3 Appendix on Using Buttons.
Open a new Flash File Action Script 2.0. Create a button like you did last lesson and name it Click to Play.
© 2011 Delmar, Cengage Learning Chapter 11 Adding Sound and Video.
Basic ActionScript and PHP Cis 126. Getting Started set up a basic folder structure so we can keep our files organized. Mirror this structure on your.
Introduction to Computer Programming - Project 2 Intro to Digital Technology.
Unit 6 Repetition Processing Instructor: Brent Presley.
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.
XP Tutorial 8 Adding Interactivity with ActionScript.
Programming in AS3. AS3 vs MXML MXML is content/structure AS3 ties in with the MXML to create the a functioning program.
Integrating Components and Dynamic Text Boxes with the Animated Map– Lesson 101 Integrating Components and Dynamic Text Boxes with the Animated Map Lesson.
CIS 205—Web Design & Development Flash Chapter 3 Working with Symbols and Interactivity.
Macromedia Flash MX Design Professional And Interactivity WORKING WITH SYMBOLS.
 Movieclip symbols are reusable pieces of flash animation  consisting usually of one or more graphic/button symbols  thus they are flash movies within.
 Motion Tween allow us to move a shape on the stage from one place to another.  In order to use motion tween, the shape to be moved must be converted.
Topic 02: Introduction to ActionScript 3.0
var variableName:datatype;
Unit Lessons Work with actions
Interface Programming 2 Week 1
Working with Symbols and Interactivity
Flash Demonstration – Unit 5 – ActionScript 3.0
Presentation transcript:

1 Flash Actionscript Adding Interactive Actions Variables

2 ActionScript 3.0 ActionScript is the language you use to add interactivity to Flash applications, whether your applications are simple animated movies or more complex rich Internet applications. You don't have to use ActionScript to use Flash, but if you want to provide basic or complex user interactivity, work with objects other than those built into Flash (such as buttons and movie clips), or otherwise turn a SWF file into a more robust user experience, you'll probably want to use it.

3 Adding an Interactive Action Start a new movie with File -> New Create a blue circle, put it in the centre of the stage, and convert it to a movie clip symbol. Call the symbol circle_mc. With the circle still selected use the properties’ panel to give this instance of circle the name ball.

4 Adding an Interactive Action So we have a symbol called circle with an instance of this symbol called ball. Now create a new layer and call it actions. Add a keyframe to the actions layer at frame 2 and add a new frame to the other layer (this is so that the first layer has two frames). We will then add actions to both of the frames on the actions layer.

5 Adding an Interactive Action Call up the Frame Actions window for frame 1 of the actions layer (right click on frame 1 and select actions). Make sure Script Assist is turned off. Type the following into the actions window this.ball.x = mouseX; this.ball.y = mouseY;

6 Adding an Interactive Action Put the following action into the Frame Actions window for frame 2 of the actions layer. gotoAndPlay (1); The second action means that the animation simply loops from 1 to 2 indefinitely.

7 Adding an Interactive Action this.ball.x = mouseX ; What does this mean? this is used to target the current timeline mouseX is the Flash way of referring to the current x coordinate of the mouse ball is the name we gave to the current instance of the circle symbol. x is the horizontal position property of that instance which we are assigning to the current value of the x position of the mouse.

8 Adding an Interactive Action We are doing the same with the value of the y and hence the blue ball will simply follow the mouse around the screen when we run the animation.

9 ActionScript Variables ActionScript is supposed to be a programming language. Program => something which receives some input, performs some processing, and does some output. Our Flash animations are interactive input = button presses, mouse events output = graphics on screen

10 ActionScript Variables So it is a programming language of sorts but so far not a very flexible one for two reasons: 1. Forms of input are a bit limited 2. It can’t remember any of its input … merely respond immediately. I think we need some variables!

11 ActionScript Variables A variable is a memory location in which a program can store data values. These values can change constantly … when a program needs to find out the current value it just looks it up. In order to be able to look up the right one it associates a unique name with each variable (chosen by the programmer).

12 Variables and Data Types You can explicitly declare the object type of a variable when you create the variable, which is called strict data typing. If you do not explicitly define an item as holding either a number, a string, or another data type, at runtime Flash Player will try to determine the data type of an item when it is assigned. Because data type mismatches trigger compiler errors, strict data typing helps you find bugs in your code at compile time and prevents you from assigning the wrong type of data to an existing variable.

13 Variables and Data Types ActionScript has the following basic data types: Boolean int uint Null Number Object String Void

14 ActionScript Variables Declaring a variable: var catName:String; You can then assign a value - done using an assignment statement which uses the assignment operator which, conveniently, is an = sign. catName = "Pirate Eye";

15 ActionScript Variables Or you can do both together: So for example the following are all valid: var hisName:String = “Pete”; var hisAge:int = 32; var gameOver:Boolean = true;

16 ActionScript Variables To view the value of a variable, use the trace() statement to send the value to the Output panel. Then, the value displays in the Output panel when you test the SWF file in the test environment. E.g., trace(hoursWorked) sends the value of the variable hoursWorked to the Output panel in the test environment.

17 ActionScript Variables Expressions We can also generate values for variables by using mathematical expressions e.g. var myAge:int = 42; var myResult:int = myAge - 10; myAge = myAge+1; var newVar:int = myResult * myAge; We can also add variables which hold things other than numbers e.g. var firstPart:String=“This is ”; var secondPart:String =“a sentence.”; var sentence:String = firstPart + secondPart; Don’t mix types in expressions though!

18 ActionScript Variables Let’s look at an example of using variables to store text inputted from the screen. 1. Open a new movie and select the Text Option. Select Input Text from the drop-down menu and click once on the stage to insert a textfield. 2. Give your textbox an instance name in1. 3. Check the border box to make Flash draw a box around the textfield.

19 ActionScript Variables If we are going to read some text in from the screen we are going to need to store it somewhere (i.e. we need a variable) We get a box into which we can type stuff. That stuff can be referred to as In1.text. We have now asked Flash to store In1.text in the string variable myTextVar. Let’s now make an output box to make sure this is happening. 4.Create a new layer and call it actions. 5.Select Frame 1 of the actions layer and open the actions panel. 6.Type in: var myTextVar:String = In1.text;

20 ActionScript Variables So we have told Flash to display the contents of in1 in the output textbox. Test the movie – why doesn’t it work? 5. Click on a blank part of the stage to deselect the input box. Click on the Text Option again and select Dynamic Text. Make sure border and Selectable are unchecked. 6.With the Text tool, add a new text field directly below the existing one. Give this one the instance name Out1. 7.Select frame 1 of the actions layer and open the actions panel. 8.Add the following to the existing code: Out1.text = myTextVar;

21 ActionScript Variables 10.Add a a frame to layer 1 and keyframe to frame 2 of your actions layer. 11.Select the keyframe and open the actions panel 12.Type in the following code: gotoAndPlay(1);

22 Variables and Scope A variable's scope refers to the area in which the variable is known (defined) and can be referenced. A global variable is one that is defined in all areas of your code, whereas a local variable is one that is defined in only one part of your code.

23 Variables and Scope In ActionScript 3.0, variables are always assigned the scope of the function or class in which they are declared. A global variable is a variable that you define outside of any function or class definition.

24 Global Variables E.g., the following creates a global variable strGlobal by declaring it outside of any function. This shows that a global variable is available both inside and outside the function definition. var strGlobal:String = "Global"; function scopeTest() { trace(strGlobal); // Global } scopeTest(); trace(strGlobal); // Global

25 Local Variables You declare a local variable by declaring the variable inside a function definition. The smallest area of code for which you can define a local variable is a function definition. A local variable declared within a function will exist only in that function.

26 Local Variables E.g., if you declare a variable named str2 within a function named localScope(), that variable will not be available outside the function. function localScope() { var strLocal:String = "local"; } localScope(); trace(strLocal); // error because strLocal is //not defined globally

27 Variable Scope If the variable name you use for your local variable is already declared as a global variable, the local definition hides (or shadows) the global definition while the local variable is in scope. The global variable will still exist outside of the function.

28 Variable Scope E.g., the following creates a global string variable named str1, and then creates a local variable of the same name inside the scopeTest() function. var str1:String = "Global"; function scopeTest () { var str1:String = "Local"; trace(str1); // Local } scopeTest(); trace(str1); // Global

29 Variable Scope The trace statement inside the function outputs the local value of the variable, but the trace statement outside the function outputs the global value of the variable.