ActionScript: Functions, Parameters, Functions that return a value, Variables, setInterval Functions MMP 220 Multimedia Programming This material was prepared.

Slides:



Advertisements
Similar presentations
Introduction to Macromedia Director 8.5 – Lingo
Advertisements

Sub and Function Procedures
Class-level Methods and Inheritance MMP 220 Multimedia Programming This adapted material was prepared for students in MMP220 as as part of a curriculum.
© 2010 Delmar, Cengage Learning Chapter 9: Using ActionScript.
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
The Web Warrior Guide to Web Design Technologies
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Eight Sub and Function Procedures.
Week 9: Methods 1.  We have written lots of code so far  It has all been inside of the main() method  What about a big program?  The main() method.
Flash Workshop Flash Workshop :: Agenda  Introductions  Look at a few Flash Examples  Flash Web Sites  Flash Web Applications  Flash Games.
B.Sc. Multimedia ComputingMultimedia Authoring Introduction to ActionScript.
1 Chapter 4 The Fundamentals of VBA, Macros, and Command Bars.
Chapter 6: Function. Scope of Variable A scope is a region of the program and broadly speaking there are three places, where variables can be declared:
Chapter 9 Introduction to ActionScript 3.0. Chapter 9 Lessons 1.Understand ActionScript Work with instances of movie clip symbols 3.Use code snippets.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
Chapter 4: Decision Making with Control Structures and Statements JavaScript - Introductory.
1 JavaScript in Context. Server-Side Programming.
Getting a handle on ActionScript A basic primer for non-programmers.
Searching and Sorting Chapter Sorting Arrays.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 7 Sub and Function Procedures.
Parameters and Event-Handler Methods MMP 220 Multimedia Programming This adapted material was prepared for students in MMP220 as as part of a curriculum.
CPS120: Introduction to Computer Science Decision Making in Programs.
CPS120: Introduction to Computer Science Lecture 14 Functions.
Functions Reusable Parts of Code SoftUni Team Technical Trainers Software University
ActionScript: Addressing Display Objects, Duplicating MovieClips, Attaching MovieClips Dynamically MMP 220 Multimedia Programming This material was prepared.
ActionScript: Loading External Content with MovieClipLoader Class, Listener Objects, Preloaders, HitTest, Loading Sound MMP 220 Multimedia Programming.
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
Chapter 2: Variables, Functions, Objects, and Events JavaScript - Introductory.
PROGRAMMING IN VISUAL BASIC.NET VISUAL BASIC PROGRAMMING FUNDAMENTALS Bilal Munir Mughal 1 Chapter-8.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 5A Repetition (Concepts)
Variables and Functions Chapter Variables Named storage location in computer’s memory Programs may need to store data when running Types of data.
JavaScript, Fourth Edition
ActionScript: For Loops, While Loops, Concatenation and Arrays MMP 220 Multimedia Programming This material was prepared for students in MMP220 Multimedia.
Classes, Objects, and World-level Methods MMP 220 Multimedia Programming This adapted material was prepared for students in MMP220 as as part of a curriculum.
ActionScript: Classes, Properties, EventHandler Methods, Datatypes & Control Structures MMP 220 Multimedia Programming This material was prepared for students.
4. Javascript M. Udin Harun Al Rasyid, S.Kom, Ph.D Lab Jaringan Komputer (C-307) Desain.
Computer Game Design ActionScript is… Object-oriented programming Everything you do in ActionScript does something to some object* Some objects.
Programming: Simple Control Structures MMP 220 Multimedia Programming This adapted material was prepared for students in MMP220 as as part of a curriculum.
Javascript Overview. What is Javascript? May be one of the most popular programming languages ever Runs in the browser, not on the server All modern browsers.
Rich Internet Applications 2. Core JavaScript. The importance of JavaScript Many choices open to the developer for server-side Can choose server technology.
Interactive Programming MMP 220 Multimedia Programming This adapted material was prepared for students in MMP220 as as part of a curriculum redesign project.
Repetition Statements (Loops). 2 Introduction to Loops We all know that much of the work a computer does is repeated many times. When a program repeats.
MIT-AITI: Functions Defining and Invoking Functions Functions as Data Function Scope: The call Object Function Arguments: The arguments objects Function.
Parameters MMP 220 Multimedia Programming This adapted material was prepared for students in MMP220 as as part of a curriculum redesign project funded.
Tutorial 11 1 JavaScript Operators and Expressions.
JavaScript and Ajax (JavaScript Functions) Week 5 Web site:
National Diploma Unit 4 Introduction to Software Development Procedures and Functions.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Programming Right from the Start with Visual Basic .NET 1/e
var variableName:datatype;
User-Written Functions
CHAPTER 4 CLIENT SIDE SCRIPTING PART 3 OF 3
Functions Chapter 6-Part 2.
Chapter 3: Using Methods, Classes, and Objects
4. Javascript Pemrograman Web I Program Studi Teknik Informatika
Using Procedures and Exception Handling
Starting Out with Java: From Control Structures through Objects
Chapter 4 LOOPS © Bobby Hoggard, Department of Computer Science, East Carolina University / These slides may not be used or duplicated without permission.
JavaScript Selection Statement Creating Array
Interface Programming 2 Week 1
T. Jumana Abu Shmais – AOU - Riyadh
Object Oriented Programming in java
Functions, Regular expressions and Events
JavaScript What is JavaScript? What can JavaScript do?
Animation Programs: Scenarios and Storyboards
Chapter 7: Using Functions, Subs, and Modules
JavaScript What is JavaScript? What can JavaScript do?
Classes, Objects and Methods
Chapter 10: Void Functions
Presentation transcript:

ActionScript: Functions, Parameters, Functions that return a value, Variables, setInterval Functions MMP 220 Multimedia Programming This material was prepared for students in MMP220 Multimedia Programming as as part of a curriculum redesign project funded by National Science Foundation grant # Co PI’s Christopher Stein and Jody Culkin BMCC CUNY

Functions Functions in ActionScript are a way of grouping a block of code that performs a specific task when that function is called. Writing functions in ActionScript is similar to writing world or class level methods in Alice.

Advantages of Functions  Code is more readable because repetition (redundancy) is eliminated.  Program is more efficient by reusing functions rather than retyping blocks of code.  Functions are centralized place to make changes in code- changes apply each time function is called.  Well-written functions can be reused in other programs, developers can build a library of functions that can be used again and again.  Encapsulating code in functions provides the basis for user interaction. A user-initiated action can invoke a function, rather than running an application as a single routine.

Writing Custom Functions Writing a function is called declaring or defining a function. Here is a model of the syntax of a function. function functionName():datatype{ statements }

Here is an example of a custom function called moveClip that moves a movieClip named square_mc 5 pixels each time it is called. function moveClip():Void{ square_mc._x +=5; }

Calling a function Like world or class level methods you defined in Alice, custom functions you define must be called in ActionScript. To call a function, you need the type the name of the function, followed by parentheses, which are called the function call operator followed by a semicolon. moveClip();

Passing Parameters Here is our moveClip function adjusted, with 2 parameters added- one refers to the name of the clip to be moved, one refers to how far the clip will be moved. function moveClip(mWhichClip:MovieClip,nDistance:Number):Void{ mWhichClip._x +=nDistance; }

Call to function with parameters As you can see, when we define our parameters, we declare their datatype. Here is the call to the function with the parameters passed in: moveClip(square_mc, 5);

Creating a Function that returns a value When we were using Alice, we used Alice’s primitive functions to ask questions about things, like distances for example. You can define a function that returns a value, using the keyword return. Here is an example that adds 2 numbers: function addThem(nA:Number, nB:Number){ var nSum = nA + nB; return nSum; }

Here we store the value returned by addThem in a variable. var nTotal:Number = addThem( ); Function Call

Variables A variable is a container or placeholder for a value. Variables can hold all different datatypes- Boolean, Numbers, Strings, Objects. var grow:Boolean = true;

Variable Scope Scope is the area within something is defined within ActionScript. In this context, we are talking about variables. Variables can have the scope (retain their value) of an entire movie, on a particular timeline, or in a particular function. A local variable is defined within a function and does not retain its value outside of that function.

Creating Interval Functions By using the setInterval() command, you can specify a function and an interval (in milliseconds) on which the function can be continually called. setInterval(moveClip,25,square_mc, 5);

In the following example, our setInterval function is stored in a variable, so we can call clearInterval when we want to stop our function from being called. var nInterval:Number = setInterval(moveClip,25,square_mc, 5); To stop the function from being called, we would clear the interval like so: ClearInterval(nInterval);

Assignment Read Chapter 4 of the ActionScript Bible Write a custom function and call it from an event handler method. You might consider writing a function that returns a value. Due Thursday April. 5.