Flash Development Guide

39
Flash Sharing Lesson 2 Flash Development Guide By Stanley Fok

description

This presentation mainly covers the following topics:- Flash Development Environment Setup- Flash Programming Model- OOP in Flash- Flash Programming Best Practice

Transcript of Flash Development Guide

Page 1: Flash Development Guide

Flash Sharing Lesson 2Flash Development Guide

By Stanley Fok

Page 2: Flash Development Guide

We will talk about…

Flash Development Environment Setup

Flash Programming Model

OOP in Flash

Flash Programming Best Practice

Page 3: Flash Development Guide

Flash Development Environment Setup

Page 4: Flash Development Guide

FlashDevelop

A famous open source ActionScript Editor

Useful Features Include: › Code hints› Code completion› Code generation› Code searching

Feature Tour: http://www.flashdevelop.org/wikidocs/index.php?title=Features:Interface

Page 5: Flash Development Guide

FlashTracer

Flash tracer is a firefox extension which enables you to see all the output generated by any running flash swf movies in browser

Download:http://www.sephiroth.it/firefox/flashtracer/

Page 6: Flash Development Guide

FlashTracer Configuration

Install Flash Debug Player› http://www.adobe.com/support/flashplayer/downloads.html

flashlog.txt path› Windows XP: C:\Documents and Settings\{user}\Application

Data\Macromedia\Flash Player\Logs\flashlog.txt› Windows Vista: C:\Users\{user}\AppData\Roaming\

Macromedia\Flash Player\Logs\flashlog.txt› Linux:

home/username/.macromedia/Flash_Player/Logs/flashlog.txt› OSX:

/Users/{username}/Library/Preferences/Macromedia/Flash Player/Logs/flashlog.txt

Page 7: Flash Development Guide

Firebug & HttpWatch

Useful to trace Request and Response between Flash Movie and Server

Firebug (only Firefox): http://getfirebug.com/

HttpWatch (IE and Firefox): http://www.httpwatch.com/

Page 8: Flash Development Guide

Flash Programming Model

Page 9: Flash Development Guide

Program Entry Point

Flash is an event-driven program

No specific program entry point› Unlike java / C, there is no “main function” as

the entry point and main loop

Code logic is usually triggered by:› Event handler› Timeline› UI Class constructor

Page 10: Flash Development Guide

Application Architecture

Code LogicActionScript

UI DefinitionFLA file

Server ResponseXML / JSON

Controller

Model View

Page 11: Flash Development Guide

Class Structure

UI Classes

Helper Classes

Data Classes

Flash Display Components

MovieClip, Sprit, …

Other Flash Core Libraries

Extends Imports / Extends

Application Libraries

AS3 Core Libraries

Page 12: Flash Development Guide

UI Class

UI Class

Tell the UI how to “react” with different events

Constructorthis.addEventListener(MouseEvent.Click, this. handleMouseClick);

Event Handlersprivate function handleMouseClick(…) {}

UI Class Pattern

Page 13: Flash Development Guide

Helper Class

Implements reusable methods / business logic which can be shared within the application / across projects, e.g.› String Operation› Server Communication› Sound Manager

Usually implemented as static class

Page 14: Flash Development Guide

Data Class

To define the variables and methods of a data object, e.g.› A user has attributes:

name gender photoPath

› And methods: save(); logOut();

Page 15: Flash Development Guide

OOP in Flash

Page 16: Flash Development Guide

Comparing AS3.0 and Java

AS 3.0 Java

Inheritance Yes Yes

Access Modifiers Yes Yes

Abstract Class No Yes

Interface Yes Yes

Function Overriding Yes Yes

Function Overloading No Yes

Private constructors No Yes

http://flexblog.faratasystems.com/?p=115

Page 17: Flash Development Guide

Demo TimeCreating Our First OOP Flash Application

Page 18: Flash Development Guide

Steps to Follow

1. FlashDevelop Setup2. Flash Movie Setup3. Define UI Tree4. Write the Classes5. Link the Classes with UI6. Compile!

Page 19: Flash Development Guide

The UI and Class Structure in this demo

Stage

iconWheelMc

infoMc iconContainerMc

coverMciconMciconMciconMc

Dynamic attach

Class: Icon

Class: IconContainer

Class: IconWheel

Page 20: Flash Development Guide

Flash Programming Best Practice

Rules to speed up development

Page 21: Flash Development Guide

Flash’s Common Problems

No standard programming framework

Long compile time

Long debug time

Involves many people within the project

Frequently changing requirement from client

Page 22: Flash Development Guide

Rule #1

Extract platform dependent config into XML files

Page 23: Flash Development Guide

Aim: Make application more portable

Platform Dependent Variables, such as› host name, › API URLshould not be hardcoded inside ActionScript

The Flash Application should be able to port onto any platform without compilation

Page 24: Flash Development Guide

Rule #2

Identify and extract frequently changing variables to XML

Page 25: Flash Development Guide

Aim: Speed up debugging time

Frequently changing variables:› Visual effect parameters› Warning messages

Compilation is not needed during test

Provide room for designer to adjust visual effect without editing ActionScript

Page 26: Flash Development Guide

Rule #3

ActionScript should be extracted out from .FLA files and write into .AS files

Page 27: Flash Development Guide

Aim: To let programmer and designer work in parallel

In the timeline of FLA, only allow:› Timeline control function,

play(), stop(), gotoAndPlay(), etc› Triggering functions defined in .AS files

Page 28: Flash Development Guide

Rule #4

Ensure Flash App is able to run in Flash IDE already / in local drive

Page 29: Flash Development Guide

Aim: Speed up debugging time

Do not need to copy the complied .SWF files to server and reload browser to debug every time

Can be achieve by:› Not using relative path for API or other assets:

Do: http://www.abc.com/php/getData.php Do not: /php/getData.php

Page 30: Flash Development Guide

Flash Player “Global Security Setting”› Allow the application access data from

other domain when testing in local drive › http://www.macromedia.com/support/documentation/en

/flashplayer/help/settings_manager04.html

Page 31: Flash Development Guide

Rule #5Ensure subsections SWF able to run independently

Page 32: Flash Development Guide

Aim: Speed up debugging time

More concentrate on debugging a Flash section

Home

Section 1 Section 2

Section 1a Debug entry point

Page 33: Flash Development Guide

Rule #6

Plan well the UI structure before development

Page 34: Flash Development Guide

Aim: › Leave room for designer

to add timeline effect› Make UI Class

independent of UI structure

Stage

iconWheelMc

infoMc iconContainerMc

coverMc

Stage

infoMc iconContainerMc coverMc

Not modulized Modulized

Page 35: Flash Development Guide

Rule #7

Avoid using parent, root

Page 36: Flash Development Guide

Aim: Make UI Code independent of UI structure

UI Structure will be usually changed during integration phase

When the Flash become very complex, you will see horrible code like:› parent.parent.parent.parent…

Please avoid it!!!

Avoid traversing the UI tree when accessing objects in other .SWF file› Try singleton or global variable (by static class

variable)

Page 37: Flash Development Guide

The “Root” reference issue

Root

home.swf

section1.swf section2.swf

section1a.swf

Root

If start from section1a.swf …

If start from home.swf …

section1a.swf

In AS 2.0…

Page 38: Flash Development Guide

The “Root” reference issue

Root

home.swf

section1.swf section2.swf

section1a.swf Root

If start from section1a.swf …

If start from home.swf …

section1a.swf

In AS 3.0…

Stage

Stage

RootRoot

Root

Page 39: Flash Development Guide

What’s coming…

Visual Effect Programming Skills