ActionScript 3.0 Basic Programming Concepts by Martin Stanhope The University of Bolton.

Slides:



Advertisements
Similar presentations
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Advertisements

Introduction to C Programming
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
Introduction to C Programming
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
Introduction to Programming with Java, for Beginners Primitive Types Expressions Statements Variables Strings.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems/Headington.
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
CS 3850 Lecture 5 Operators. 5.1 Binary Arithmetic Operators Binary arithmetic operators operate on two operands. Register and net (wire) operands are.
SM1205 Interactivity Topic 02: ActionScript 3.0 Fundamentals - Part I Hongbo Fu Spring 2011SCM-CityU1.
Chapter 2: Introduction to C++.
Introduction to C Programming
VB .NET Programming Fundamentals
Lights, Camera, ActionScripts Web Design ½ Shade Adetoro.
 Value, Variable and Data Type  Type Conversion  Arithmetic Expression Evaluation  Scope of variable.
JavaScript – Part II Data Types and Operations George Mason University June 3, 2010.
Simple Programs from Chapter 2 Putting the Building Blocks All Together (corresponds with Chapter 2)
 Input and Output Functions Input and Output Functions  OperatorsOperators Arithmetic Operators Assignment Operators Relational Operators Logical Operators.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
CIS 260: App Dev I. 2 Programs and Programming n Program  A sequence of steps designed to accomplish a task n Program design  A detailed _____ for implementing.
Chapter 2 Overview of C++. A Sample Program // This is my first program. It calculates and outputs // how many fingers I have. #include using namespace.
Introduction to PHP A user navigates in her browser to a page that ends with a.php extension The request is sent to a web server, which directs the request.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
Arithmetic Operations. Review function statement input/output comment #include data type variable identifier constant declaration.
M.T.Stanhope Oct Title : C++ Basics Bolton Institute - Faculty of Technology (Engineering) 1 C++ Basics u Data types. u Variables and Constants.
CIS 260: App Dev I. 2 Programs and Programming n Program  A sequence of steps designed to accomplish a task n Program design  A detailed _____ for implementing.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
1 st Semester Module2 Basic C# Concept อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering.
Introduction to Programming with RAPTOR
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
Programming Fundamental Slides1 Data Types, Identifiers, and Expressions Topics to cover here: Data types Variables and Identifiers Arithmetic and Logical.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
Controlling Program Flow. Data Types and Variable Declarations Controlling Program Flow.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
SE-1010 Dr. Mark L. Hornick 1 Variables & Datatypes.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
PHY-102 SAPVariables and OperatorsSlide 1 Variables and Operators In this section we will learn how about variables in Java and basic operations one can.
Introducing C++ Programming Lecture 3 Dr. Hebbat Allah A. Elwishy Computer & IS Assistant Professor
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Module 5 JavaScript Operators. CS346 Javascript-52 Examples  JS-5 Examples.
Variables 1. What is a variable? Something whose value can change over time This value can change more than once over the time period (no limit!) Example:
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
1 st Semester Module2 Basic C# Concept อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering.
OPERATORS IN C CHAPTER 3. Expressions can be built up from literals, variables and operators. The operators define how the variables and literals in the.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Topic 02: Introduction to ActionScript 3.0
University of Central Florida COP 3330 Object Oriented Programming
Chapter 2 - Introduction to C Programming
Computing Fundamentals
2.5 Another Java Application: Adding Integers
Object Oriented Programming
University of Central Florida COP 3330 Object Oriented Programming
Data Types, Identifiers, and Expressions
Chapter 2 - Introduction to C Programming
Operators and Expressions
Data Types, Identifiers, and Expressions
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Chapter 2: Introduction to C++.
Chapter 2 - Introduction to C Programming
Unit 3: Variables in Java
ENERGY 211 / CME 211 Lecture 5 October 1, 2008.
Introduction to C Programming
Presentation transcript:

ActionScript 3.0 Basic Programming Concepts by Martin Stanhope The University of Bolton

What is AS3? ActionScript 3.0 (AS3) in an object-oriented programming (OOP) language used to create Flash movies (swf files). It is integrated into the Abobe Flash CS5 application. ActionScript has been developed over the years from AS1 to AS2 and now, with the latest releases of Adobe Flash, it has matured to become version 3.0. AS3 is a major step forward from AS2 in that it has become a full-featured object-oriented programming language.

Program comments Always place comments in your AS3 program code to indicate to the reader what the code is for. Single line comments begin with // Multiple line comments are bounded by /* and */ The multiple line method is very useful for temporarily ‘commenting out’ a section of code during debugging.

Constants, variables and data types Constants. Values that do not change (i.e. remain constant) can be assigned to meaningful names which can then be used throughout the program to represent the value. E.g. const VAT = 17.5; Capital letters are normally used for constants so they are obvious to the program reader. Variables are named memory locations used to store data of a specific type (uint, int, Number, String), e.g. var playerName:String = “Captain Scarlet”; var age:uint = 30; var bodyTemperatureDegC:Number = 36.9;

Simple debugging using trace() Trace is an AS3 built-in function giving the developer a means of displaying program output (e.g. the contents of variables) to an output window for the purpose of program debugging and development. // A simple example of the use of the trace function trace(“Player’s name is “ + playerName); trace(“Current age is “ + age); trace(“Body temperature is “ + bodyTemperatureDegC + “ degrees Celcius.”);

Operators Arithmetic +, -, *, /, % Conditional ==, !=,, >= Logical &&, ||, ! Bitwise >, &, |, ^, ~ Assignment= Reassignment+=, -=, *=, etc...

Operators - Arithmetic Arithmetic operators... +, -, *, /, % Example: var x:int = 6; var y:int = 4; var z:Number = 0;// Note the data type z = x + y; trace(z); // Displays 10 z = x - y; trace(z); // Displays 2 z = x * y; trace(z); // Displays 24 z = x / y; trace(z); // Displays 1.5 z = x % y; trace(z); // Displays 2, the remainder

Operators Precedence and Associativity Operator precedence: The order of operation trace( * 10); // displays 32 not 50 trace( 12 / 4 – 2); // displays 1 not 6 Operator associativity (left or right ?) trace( 2 * 6 / 3); // displays 4 as the operators // of the same precedence work left to right z = x = y; //The assignment operator trace(z); // uses right to left associativity so this displays 4

Using the + operator with strings The + operator is also used to concatenate (join) strings together as shown below... var firstname:String = “Joe”; var lastname:String = “Bloggs”; var String = trace(“Student details are “ + firstname + “ “ + lastname + “ “ + );

Operators - Conditional Conditional operators: ==, !=,, >= var x:uint = 6; var y:uint = 4; var s1:String = “abc”; var s2:String = “bcd”; var result:Boolean; result = ( x == y ); trace(result) ; // displays FALSE result = ( x != y ); trace(result) ; // displays TRUE result = ( x < y ); trace(result) ; // displays TRUE result = ( x <= y ); trace(result) ; // displays TRUE result = ( x > y ); trace(result) ; // displays FALSE result = ( x >= y ); trace(result) ; // displays FALSE result = ( s1 < s2); trace(result) ; // displays TRUE

Operators - Logical Logical (Boolean) operators: &&, ||, ! var a:Boolean = true; var b:Boolean = false; var c:Boolean = true; var result:Boolean; result = ( a && b); trace(result); //displays false result = ( a && c); trace(result); //displays true result = ( a || b); trace(result); //displays true result = ( a || c); trace(result); //displays true result = !a; trace(result); //displays false result = !b; trace(result); //displays true

Operators - Bitwise Bitwise shift left << Bitwise shift right >> Bitwise AND & Bitwise OR | Bitwise Exclusive OR (XOR) ^ Bitwise inversion (NOT) ~

Operators – Bitwise - Examples var a:uint = 8; // Binary var b:uint = 12;// Binary var result:uint; result = ( a << 1); trace (result); //displays i.e 16 result = ( a >> 1); trace (result); //displays i.e 4 result = ( a & b); trace (result); //displays i.e 8 result = ( a | b); trace (result); //displays i.e 12 result = ( a ^ b); trace (result); //displays i.e 4 result = ~a; trace (result); //displays i.e.247

Assignment operator = Assignment occurs right to left... i. At the time a variable is declared… var degF:Number = 98.4; ii. At a later stage within the program… degF = 99.2; iii. Using a value returned by a function degC = convertToCentigrade(degF);

Reassignment operators There are numerous reassignment operators such as: +=, -=, *= etc. and they behave as follows: var x:int = 2; x = x + 5 ; // x now holds 7 x += 5;// x now holds 12 x -= 3;// x now holds 9

AS3 program structure - MyTest1.as package { import flash.display.Sprite; public class MyTest1 extends Sprite { public function MyTest1() { //This shows a message in a debugging window trace(“Hello World – AS3 has arrived!”); }

AS3 program structure - MyTest2.as package { import flash.display.Sprite; public class MyTest2 extends Sprite { public function MyTest2() { //Displays 100 lines drawn between random points on the stage graphics.lineStyle(1, 0, 1); //Set the line style for(var i:int ; i<100 ; i++) { graphics.lineTo( Math.random()*300, Math.random()*300); }

AS3 code At this point you won’t understand the structure of the ActionScript code, but note the following… – The program filename has the extension.as – The filename agrees with the name of the class and the name of the function within the class – To test the operation of, say, MyTest1.as you will need to create a Flash application named MyTest.fla and in it set the ‘Document class’ parameter to MyTest1. – When the work is ‘published’ the file MyTest1.swf file is created (i.e. the final goal). – You will be amazed at how Flash movies can be created by using programming code instead of by drawing on the timeline.

File locations Get organised before you start. Create a folder for this module. Create a subfolder named as3work