Building Flash-based websites using Adobe Flex - Lesson 4/10

12

Click here to load reader

description

Building Flash-based websites using Flex Lesson 4 – Actionscript Essentials by Alex goh, associate trainer @ LAB School ( http://lab.edu.sg/ ), Adobe Authorized Training Centre, Singapore

Transcript of Building Flash-based websites using Adobe Flex - Lesson 4/10

Page 1: Building Flash-based websites using Adobe Flex - Lesson 4/10

Building Flash-based websites using Flex

Lesson 4 – Actionscript Essentials

Alex [email protected]

Page 2: Building Flash-based websites using Adobe Flex - Lesson 4/10

Agenda

● Overview of Actionscript 3.0

● Variables and data types

● Conditionals

● Loops

● Functions

● Binding to variables

Page 3: Building Flash-based websites using Adobe Flex - Lesson 4/10

Flash Platform

Actionscript

Flash Flex Framework

.swf .swf

Overview of Actionscript 3.0

Page 4: Building Flash-based websites using Adobe Flex - Lesson 4/10

● While MXML is sufficient for drawing the user interface on screen, embedding user interactions and changing application behaviour requires executing scripts (similar to the role Javascript plays in HTML documents).

● Why Actionscript 3.0 (AS3) was introduced?

● Needed a Object-oriented Programming Language to support large-scaled application development

● An attempt to bring developers on board onto the Flash platform, which was traditionally regarded as a playground for designers

● AS3 is based on ECMAScript, the same scripting engine of Java, hence, Java developers will find it easier to learn AS3.

P.S. Many products from Adobe are Java-based. (e.g. Coldfusion, BlazeDS, LiveCycle ES)

Overview of Actionscript 3.0

Page 5: Building Flash-based websites using Adobe Flex - Lesson 4/10

● Syntax:

● e.g.

● Common data types

Variables and Data Types

Page 6: Building Flash-based websites using Adobe Flex - Lesson 4/10

● In many cases, the program needs to behave differently or execute different codes based on certain scenarios.

● The most common conditional statement is the if-else statement.

● Syntax:

Conditionals – if-else statement

Page 7: Building Flash-based websites using Adobe Flex - Lesson 4/10

● If more than 2 test cases, include else-if statements.

● Syntax:

Conditionals – if-else statement

Page 8: Building Flash-based websites using Adobe Flex - Lesson 4/10

● Conditional operators are used to validate the test cases in the if clause.

Conditionals – Conditional Operators

Page 9: Building Flash-based websites using Adobe Flex - Lesson 4/10

● To include more than one test cases within a if or else-if clause.

Conditionals – Compound conditions

Page 10: Building Flash-based websites using Adobe Flex - Lesson 4/10

● Loops cause a block of codes to execute repeatedly, for as long as its test case holds true.

● All common looping methods are available in AS3:

● while loop● do-while loop● for loop

● for loop:

Loops

Page 11: Building Flash-based websites using Adobe Flex - Lesson 4/10

● A function is a grouping of a block of codes that can be executed when called.

● Reasons for using function:

● Reusability● Event handling

● e.g.

Functions

Page 12: Building Flash-based websites using Adobe Flex - Lesson 4/10

● Ensure a property or variable always get the latest value of another property or variable

● e.g.

Binding to Variables