Programming in AS3. AS3 vs MXML MXML is content/structure AS3 ties in with the MXML to create the a functioning program.

Slides:



Advertisements
Similar presentations
L2:CSC © Dr. Basheer M. Nasef Lecture #2 By Dr. Basheer M. Nasef.
Advertisements

Programming C/C++ on Eclipe Trình bày : Ths HungNM C/C++ Training.
JavaScript Part for Repetition Statement for statement Cpecifies each of the items needed for counter-controlled repetition with a control variable.
Variable types We have already encountered the idea of a variable type. It is also possible to think about variables in terms of their kind, namely: 1)
Data Types in Java Data is the information that a program has to work with. Data is of different types. The type of a piece of data tells Java what can.
VBA Modules, Functions, Variables, and Constants
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
MIRC Matthew Forest. Introduction mIRC itself is a program designed for text based messaging via the IRC (internet relay chat) protocol. (Link:
Java Programming, 3e Concepts and Techniques Chapter 3 Manipulating Data Using Methods.
1 Flash Actionscript Adding Interactive Actions Variables.
CS102 Data Types in Java CS 102 Java’s Central Casting.
SUNY Morrisville-Norwich Campus-Week 12 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith.
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Day 4 Objectives Constructors Wrapper Classes Operators Java Control Statements Practice the language.
Chapter 3: Using Variables and Constants
WEB DESIGN AND PROGRAMMING Introduction to Javascript.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009.
Variables & Data types Flash ActionScript 3.0 Introduction to Thomas Lövgren, Flash developer
XP New Perspectives on Microsoft Office Access 2003 Tutorial 11 1 Microsoft Office Access 2003 Tutorial 11 – Using and Writing Visual Basic for Applications.
Tutorial 11 Using and Writing Visual Basic for Applications Code
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
1 Chapter 2 Primitive Data Types and Operations F Introduce Programming with an Example  The MyInput class F Identifiers, Variables, and Constants F Primitive.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
CSC3315 (Spring 2009)1 CSC 3315 Programming Languages Hamid Harroud School of Science and Engineering, Akhawayn University
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Fund Raiser Application Introducing Scope, Pass-by-Reference and Option Strict.
Lecture 2 Object Oriented Programming Basics of Java Language MBY.
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 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
Iterative Constructs Review l What are named constants? Why are they needed? l What is a block? What is special about declaring a variable inside a block?
Lab 3: Actionscript User Interface Lab: GUI Lab Sep. 11 th, 2012.
 2005 Pearson Education, Inc. All rights reserved Methods: A Deeper Look.
CPS120: Introduction to Computer Science Decision Making in Programs.
CPS120: Introduction to Computer Science Lecture 14 Functions.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Selection Statements Selection Switch Conditional.
Applications Development
Dr. Qusai Abuein1 Internet & WWW How to program Chap.(6) JavaScript:Introduction to Scripting.
C# C1 CSC 298 Elements of C# code (part 1). C# C2 Style for identifiers  Identifier: class, method, property (defined shortly) or variable names  class,
JavaScript, Fourth Edition
COP3502 Programming Fundamentals for CIS Majors 1 Instructor: Parisa Rashidi.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Three Memory Locations and Calculations.
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Three Using Variables and Constants.
CREATING STORED PROCEDURES AND FUNCTIONS. Objectives After completing this lecture, you should be able to do the following: Differentiate between anonymous.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.1.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
1 Chapter 3 – Examples The examples from chapter 3, combining the data types, variables, expressions, assignments, functions and methods with Windows controls.
Programming with Microsoft Visual Basic th Edition
1 Writing Software Kashef Mughal. 2 Algorithms  The term algorithm (pronounced AL-go-rith-um) is a procedure or formula for solving a problem.  An Algorithm.
110 E-1 Variables, Constants and Calculations(2) Chapter 3: Operations on variables, scope of a variable, formatting data Doing Arithmetic.
Controlling Program Flow with Decision Structures.
 Static  Example for Static Field  Example for Static Method  Math class methods  Casting  Scope of Declaration  Method Overloading  Constructor.
JavaScript Events Java 4 Understanding Events Events add interactivity between the web page and the user You can think of an event as a trigger that.
JavaScript and Ajax (JavaScript Environment) Week 6 Web site:
Data Mangling The key to data-management within your Flex Applications.
JavaScript Events. Understanding Events Events add interactivity between the web page and the user Events add interactivity between the web page and the.
National Diploma Unit 4 Introduction to Software Development Procedures and Functions.
Chapter 4.  Variables – named memory location that stores a value.  Variables allows the use of meaningful names which makes the code easier to read.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 10 Java Fundamentals Objects/ClassesMethods.
Chapter 9: Value-Returning Functions
A variable is a name for a value stored in memory.
© 2016, Mike Murach & Associates, Inc.
Java Primer 1: Types, Classes and Operators
Iterative Constructs Review
JavaScript Fundamentals
Iterative Constructs Review
Chapter 6 – Methods Topics are:
Java Programming Language
Java’s Central Casting
Chapter 2 Primitive Data Types and Operations
Presentation transcript:

Programming in AS3

AS3 vs MXML MXML is content/structure AS3 ties in with the MXML to create the a functioning program

The Script Tag We include AS3 inside a script block When you type the script tag and hit enter FD will automatically create a CDATA block and here is where all the true coding begins!

<![CDATA[ //AS3 goes here ]]>

Functions Everything in flash is based off of functions Here is the format for an AS3 function: scope function name(parameters):return type { Body }

Example private function test():void { } This function does nothing Its named test It returns nothing Its scope is set to private

Event Based Programming Functions are called by the programmer or by the program when an event occurs Events are properties of a control The button is set to be clicked and when it is the test() function will be called

The Code <![CDATA[ import mx.controls.*;//import the library/package containing the control classes private function test():void { Alert.show("Hello world!"); } ]]>

The Import Statements These are required when using classes in certain packages Since the Alert class exists in the mx.controls package we import it by importing everything in that package We could have also written import mx.controls.Alert; Be aware of the followig error, as it is due to not importing the proper package G:\projects\prjFlex2\src\Main.mxml(19): Error: Access of undefined property Alert.

What Events? FD helps you with this in its popup window (events have a lighting bolt symbol) You could also research the reference info at reference/actionscript/3/mx/controls/Button. html#protectedMethodSummary reference/actionscript/3/mx/controls/Button. html#protectedMethodSummary Search for the events section

Variables The format for variable declaration is: var name:type; A primitive value is a value that belongs to one of the following data types: String, Number, int, uint, Boolean, Null, and void. A complex value is a value that is not a primitive value. Data types that define sets of complex values include: Object,Array, Date, Error, Function, RegExp, XML, and XMLList. All values in ActionScript 3, whether they are primitive or complex, are objects.

Sample Code private function test():void{ var n1:Number; var n2:Number; n1 = Number(txtNumber1.text); n2= Number(txtNumber2.text); var answer:Number; answer = n1 + n2; Alert.show("Answer is " + answer); }

Type conversions Number() is a built in function that converts non-numbers to number types A type conversion is said to occur when a value of one data type is transformed into a value of a different data type. Type conversions can be either implicit or explicit. Implicit conversion, also called coercion, is sometimes performed at runtime. For example, if the value 2 is assigned to a Boolean typed variable, the value 2 is converted to the Boolean value true before assignment. Explicit conversion, also called casting, occurs when your code instructs the compiler to treat a variable of one data type as if it belongs to a different data type. When primitive values are involved, casting actually converts values from one data type to another. To cast an object to a different type, you wrap the object name in parentheses and precede it with the name of the new type. For example, the following code takes a Boolean value and casts it to an integer:

var myBoolean:Boolean = true; var myINT:int = int(myBoolean); trace(myINT); // 1 Implicit conversions Implicit conversions happen at runtime in a number of contexts: In assignment statements When values are passed as function arguments When values are returned from functions In expressions using certain operators, such as the addition (+) operator Explicit conversions It's helpful to use explicit conversions when you compile in strict mode, because there are times when you do not want to generate a compile-time error. Use explicit conversions when you know that coercion will convert your values correctly at runtime. For example, when working with data received from a form, cast certain string values to numeric values. The following code generates a compile-time error even though the code would run correctly in standard mode: var quantityField:String = "3"; var quantity:int = quantityField; // compile time error in strict mode If you want to continue using strict mode, but would like the string converted to an integer, you can use explicit conversion, as follows: var quantityField:String = "3"; var quantity:int = int(quantityField); // Explicit conversion succeeds.

Default Values Data typeDefault value Booleanfalse int0 NumberNaN Objectnull Stringnull uint0

Exercises Create a program that allows a user to enter the cost of 4 items, a tax rate and a discount rate (both in percentages). It then displays the final pre-tax cost, cost wit tax, discount applied to this final cost and then the final discounted cost (all in a nicely designed and labeled GUI). Make sure you use the proper type and number of variables as well as incorporate the necessary type conversions. Post your project to your unit 1 webpage.