SM1205 Interactivity Topic 03: Flow Control Spring 2010SCM-CityU1.

Slides:



Advertisements
Similar presentations
Introduction to Macromedia Director 8.5 – Lingo
Advertisements

Introduction to Programming using Matlab Session 2 P DuffourJan 2008.
CS0007: Introduction to Computer Programming
© 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.
SM1205 Interactivity Topic 04: Properties and Events Spring 2010SCM-CityU1.
Introducing ActionScript 3.0 Object-oriented programming language Used to power Flash Player Similar to JavaScript Can be embedded in a Flash project.
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 Adding Interactive Actions Variables.
SM1205 Interactivity Topic 04: Properties and Events Part I Spring 2011SCM-CityU1.
CIS101 Introduction to Computing Week 11. Agenda Your questions Copy and Paste Assignment Practice Test JavaScript: Functions and Selection Lesson 06,
Kapi’olani Community College Art 258 Interface Programming II In-class Presentation Week 5A.
SM1205 Interactivity Topic 02: ActionScript 3.0 Fundamentals - Part I Hongbo Fu Spring 2011SCM-CityU1.
SM1205 Interactivity Topic 11: Motion Tracking Part III Spring 2010SCM-CityU1.
Tutorial 4 Decision Making with Control Structures and Statements Section A - Decision Making JavaScript Tutorial 4 -Decision Making with Control.
CIS101 Introduction to Computing Week 12 Spring 2004.
1 Flash Programming Introduction Script Assist. 2 Course Description This course concentrates on the teaching of Actionscript, the programming language.
SM1205 Interactivity Topic 06: Iteration and Multiple Objects Spring 2010SCM-CityU1.
Utah State Button Symbols, Bitmaps, Actionscripting.
“But I don't want to be a “programmer!” ActionScript for journalists Presentation by Mindy McAdams Flashjournalism.com.
AD 206 Intermediate CG : School of Art and Design : University of Illinois at Chicago : Spring 2009 Intro to Action Script 9 "The games of a people reveal.
© 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 9 Interactive Multimedia Authoring with Flash - Introduction to Programming “Computers and Creativity” Richard D. Webster, COSC 109 Instructor.
XP Tutorial 5 Buttons, Behaviors, and Sounds. XP New Perspectives on Macromedia Flash MX Buttons Interactive means that the user has some level.
PROGRAMMING IN VISUAL BASIC.NET VISUAL BASIC BUILDING BLOCKS Bilal Munir Mughal 1 Chapter-5.
© 2011 Delmar, Cengage Learning Chapter 9 Introduction to ActionScript 3.0.
Python Programming Using Variables and input. Objectives We’re learning to make use of if statements to enable code to ask questions. Outcomes Build an.
COIT29222 Structured Programming Slide 1 COIT29222-Structured Programming Lecture Week 06  Reading: Study Guide Book 2, Modules 9 & 10 Textbook (4 th.
Dr. Yang, QingXiong (with slides borrowed from Dr. Yuen, Joe) LT3: Conditional Statements CS2311 Computer Programming.
1 Conditions Logical Expressions Selection Control Structures Chapter 5.
1. We’ve learned that our programs are read by the compiler in order, from top to bottom, just as they are written The order of statement execution is.
Tutorial 8 Programming with ActionScript 3.0. XP Objectives Review the basics of ActionScript programming Compare ActionScript 2.0 and ActionScript 3.0.
Getting a handle on ActionScript A basic primer for non-programmers.
SM1205 Interactivity Topic 06: Iteration and Multiple Objects Spring 2012SCM-CityU1.
7-1 OBJ Copyright 2003, Paradigm Publishing Inc. Using ActionScript and Creating Templates Macromedia Flash Design & Application.
Creating Buttons – Lesson 71 Creating Buttons Lesson 7.
AD 206 Intermediate CG : School of Art and Design : University of Illinois at Chicago : Spring 2009 Intro to Action Script "The games of a people reveal.
Coding Design Tools Rachel Gauci. Task: Counting On Create a program that will print out a sequence of numbers from "1" to a "number entered”. Decision’s.
Applications Development
Conditional Expression One of the most useful tools for processing information in an event procedure is a conditional expression. A conditional expression.
JavaScript - Basic Concepts Prepared and Presented by Hienvinh Nguyen, Afshin Tiraie.
XP Tutorial 8 Adding Interactivity with ActionScript.
JavaScript, Fourth Edition
Lesson Two: Everything You Need to Know
Programming games Problems. Schedule Various examples. Homework: rps, bo (don't go back to do this), cannonball, Video or Audio should be complete. Now.
Quiz 3 is due Friday September 18 th Lab 6 is going to be lab practical hursSept_10/exampleLabFinal/
1 Actionscript for Flash by Dr SC Li. 2 Understanding more about instances Symbolsgraphics buttons Movie clips Instances (without names) No interaction.
More Python!. Lists, Variables with more than one value Variables can point to more than one value at a time. The simplest way to do this is with a List.
SCRIPT PROGRAMMING WITH FLASH Introductory Level 1.
CIS 205—Web Design & Development Flash Chapter 3 Appendix on Using Buttons.
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.
Open a new Flash File Action Script 2.0. Create a button like you did last lesson and name it Click to Play.
Controlling Program Flow with Decision Structures.
XP Tutorial 8 Adding Interactivity with ActionScript.
Copyright © Don Kussee 1410-Ch5 #1031 CNS 1120 Chapter 5 Selection statements 1120-Ch5.PPT.
IST 210: PHP LOGIC IST 210: Organization of Data IST210 1.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
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.
IST 210: PHP Logic IST 210: Organization of Data IST2101.
 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
The Little Crab Scenario
Interface Programming 2 Week 1
Items, Group Boxes, Check Boxes & Radio Buttons
Logical Operations In Matlab.
Using Functions
Selection Statements.
Presentation transcript:

SM1205 Interactivity Topic 03: Flow Control Spring 2010SCM-CityU1

Button Simplest UI element Map action to each button Spring 2010SCM-CityU2 press perform action

Exercise Use 2 buttons to control the size of the photo Spring 2010SCM-CityU3

Album Example Two buttons for nagviation (Previous & Next) Spring 2010SCM-CityU4

Album Example Load Image sequence as keyframes – Create new Flash file (AS3.0) – Open menu item “File => Import => Import to stage” – Select the first photo file (d/l from course homepage) – The system finds image sequence, answer “Yes” to load the all files Spring 2010SCM-CityU5

Album Example Add Controls Add one more layer (layer2) Add two buttons to this layer (btn_prev, btn_next) – Open “Window => Common library => buttons” – Select and add the button you like Add a dynamic text field (txt_index) Spring 2010SCM-CityU6

Album Example Add ActionScript & test the behavior Goto frame 1 layer 2 Open the action panel (press F9) Type the code in next slide – We will explain the code Press Ctrl+Enter to test the movie You can press the buttons to view the previous/next photo Spring 2010SCM-CityU7

Album Example stop(); txt_index.text = currentFrame + "/" + totalFrames; btn_prev.addEventListener(MouseEvent.CLICK, onPrevButtonClick); btn_next.addEventListener(MouseEvent.CLICK, onNextButtonClick); function onPrevButtonClick(e:MouseEvent) : void { prevFrame(); txt_index.text = currentFrame + "/" + totalFrames; } function onNextButtonClick(e:MouseEvent) : void { nextFrame(); txt_index.text = currentFrame + "/" + totalFrames; } Spring 2010SCM-CityU8

Album Example Simple movie control – currentFrame – Current frame number – totalFrames – total frames = last frame number – stop() – stop (pause) the movie – play() – play the movie, starting from current frame – prevFrame() – goto the previous frame – nextFrame() – goto the next frame – gotoAndPlay(f) – goto frame f and play the movie – gotoAndStop(f) – goto frame f and stop the movie Spring 2010SCM-CityU9

Album Example Handle mouse click events – Add event listener btn_prev.addEventListener(MouseEvent.CLICK, onPrevButtonClick); btn_next.addEventListener(MouseEvent.CLICK, onNextButtonClick); – Add event handlers function onPrevButtonClick(e:MouseEvent) : void { prevFrame(); txt_index.text = currentFrame + "/" + totalFrames; } function onNextButtonClick(e:MouseEvent) : void { nextFrame(); txt_index.text = currentFrame + "/" + totalFrames; } Spring 2010SCM-CityU10

Album Example We can go from first photo to last photo How about we press the previous button when we at the first photo – No effect? – Goto the last photo? How to achieve this? Spring 2010SCM-CityU11

How About IF… If structure – only run the process B if the condition A is true Spring 2010SCM-CityU12 Condition A Process B true false if

How About IF… if (condition) { // process } Spring 2010SCM-CityU13 Syntax – if statement – Start with “if” keyword – Condition put in parentheses – Process put in braces – Each pair of braces defines a block, which groups a set of statements together

How About IF… Condition in AS is a condition expression – Has value true / false (boolean value) – Usually is a comparison expression – E.g. a = c, a == b Comparison Operators – equal (==), not equal (!=) – Less than ( ), – less than or equal to ( =) Spring 2010SCM-CityU14

How About IF… var a:int = 1; var b:int = 1; if (a == b) { trace(“same”); } Spring 2010SCM-CityU15 Examples var flag:Boolean = true; if (flag == true) { trace(“yes”); } var flag:Boolean = true; if (flag) { trace(“yes”); } Output: “same” Output: “yes”

How About IF… Album Example function onPrevButtonClick(e:MouseEvent) : void { if (currentFrame > 1) { prevFrame(); } if (currentFrame == 0) { gotoAndStop(totalFrames); } txt_index.text = currentFrame + "/" + totalFrames; } function onNextButtonClick(e:MouseEvent) : void { if (currentFrame < totalFrames) { nextFrame(); } if (currentFrame == totalFrames) { gotoAndStop(1); } txt_index.text = currentFrame + "/" + totalFrames; } Spring 2010SCM-CityU16 Test the movie again after modified the code!

How About IF… Sometime we need to combine conditions and test them in a single if statement – E.g. age > 21 and gender == “male” Logical Operators – and (&&), or (||), not (!) Spring 2010SCM-CityU17

How About IF… var a:int = 13; var b:int = 12; if (a>10 && b>10) { trace(“>10”); } Spring 2010SCM-CityU18 Examples var pass:Boolean = true; var score = 50; if (!flag || score<60) { trace(“fail”); } Output: “>10” Output: “fail”

How About IF… var a:int = 13; var b:int = 12; if (a>10 && b>10) { trace(“>10”); } Spring 2010SCM-CityU19 Examples var pass:Boolean = true; var score = 50; if (!flag || score<60) { trace(“fail”); } Output: “>10” Output: “fail”

If-else structure – if the condition A is true, run process B, otherwise run process C Or ELSE… Spring 2010SCM-CityU20 Condition A Process B true false if Process C

Or ELSE… Syntax – if-else statement – Start with “if” keyword – Condition put in parentheses – Process A put in braces after “if” keyword – “else” keyword put after Process A – Process B put after “else” keyword Spring 2010SCM-CityU21 if (condition) { // process A } else { // process B }

Or ELSE IF… Example Spring 2010SCM-CityU22 var age:int = 20; if (age >= 21) { trace(“adult”); } else { trace(“child”); } Output: “child”

Or ELSE IF… Album Example function onPrevButtonClick(e:MouseEvent) : void { if (currentFrame > 1) { prevFrame(); } else { gotoAndStop(totalFrames); } txt_index.text = currentFrame + "/" + totalFrames; } function onNextButtonClick(e:MouseEvent) : void { if (currentFrame < totalFrames) { nextFrame(); } else { gotoAndStop(1); } txt_index.text = currentFrame + "/" + totalFrames; } Spring 2010SCM-CityU23 Test the movie again after modified the code!

Or ELSE IF… We can use else-if structure to check multiple conditions – Grouping two or more if-else statement together – Beware how “if” and “else” are matched Spring 2010SCM-CityU24

Or ELSE IF… Spring 2010SCM-CityU25 Condition A Process C true false if Process C Condition B false Process D else-if true second if-else statement

Or ELSE IF… Syntax Spring 2010SCM-CityU26 var age:int = 15; if (age >= 21) { trace(“adult”); } else if (age > 12) { trace(“teen”); } else { trace(“child”); } Output: “teen” The code in bolded is the second if-else statement

Exercise 1.Use 4 buttons to move the Flash icon in the display area 2.Add checking so that the icon does not go outside the window Spring 2010SCM-CityU27

Write-once, Run-many Function – A portion of code within a larger program – Performs a special task – Relatively independent to other part of the program – Can be used many time Examples – prevFrame(); – gotoAndStop(); Spring 2010SCM-CityU28

Write-once, Run-many Function – can be called several times from several places in the program – After calling a function, will “return” to the next instruction after the “function call” Spring 2010SCM-CityU29 function onPrevButtonClick(e:MouseEvent) : void { prevFrame(); // call function prevFrame(); // after called prevFrame(), start to execute next statement txt_index.text = currentFrame + "/" + totalFrames; }

Write-once, Run-many Surely, we call define our own function Syntax Spring 2010SCM-CityU30 function yourFunctionName(): void { // place your code here // can use multiple statements }

Write-once, Run-many examples Spring 2010SCM-CityU31 function printAtoE(): void { trace(“A”); trace(“B”); trace(“C”); trace(“D”); trace(“E”); }

Write-once, Run-many Functions often have parameters as input values – to define action of functions – more flexible control – Dynamic behaveior Syntax Spring 2010SCM-CityU32 function name(parameter:type, parameter:type, …): void { // place your code here // can use multiple statements }

Write-once, Run-many examples Spring 2010SCM-CityU33 function addAndPrint(a:int, b:int): void { var sum:int = a + b; trace(sum); } function displaceIcon(x:int, y:int): void { myIcon.x += x; myIcon.y += y; }

Write-once, Run-many Functions can have return value as output values – to define result of functions – Similar to mathematic function, e.g. f(x) = 2x – Syntax Spring 2010SCM-CityU34 f(1) = 2 f(2) = 4 f(13) = 26 … function name(parameter:type, …): returnType { // place your code here // remember to return a value after computation return x; }

Write-once, Run-many examples Spring 2010SCM-CityU35 var x:int = 10; var y:int = 7; Var result:int = addThreeInt(x, y, 5); function addThreeInt(a:int, b:int, c:int): int { var sum:int = a + b + c; return sum; }