Accessibility
Giacomo Guilzzoni

Giacomo Guilizzoni

Macromedia

Created:
16 May 2005
User Level:
Intermediate
Products:
Flashcom

Peldi's Coding Café: Flash Communication Server Best Practices

This is an archive of a live discussion that I presented on Flash Communication Server best practices. Programming Flash Communication Server applications is not an easy task, but after you have built a few (or a few dozen), some patterns start to emerge. Learn these patterns and get a peek at the best practices that I use to build Breeze Meeting using Flash Communication Server.

What You Will Learn

In this session I will build a very simple shared text application, which uses a Remote Shared Objects to share the text amongst all the users connected to it. Using as many best practices as possible when building even a small application like this one will help you when it’s time to expand it and maintain its code six months later.

I thought it would be useful to give you a timeline showing some of the topics in this hour-long presentation. Here's an outline of what I covered, and the approximate time in the archive where it's covered:

Introduction

  • Demo of the sample application (2:00)

Creating a FLA File

  • Building an AS2-ready FLA and a Main class (3:00)
  • 2-frame-timeline for a class (3:45)
  • Keeping all of your code out of the FLA (5:00)
  • Linkage name same as class name (including namespace) (6:05)

The main.as File

  • Extending MovieClip versus extending Object (seek to 6:50)
  • Importing * versus importing a single component (8:00)
  • How to declare your variables (9:00)
  • Keeping your z-layers organized (10:00)
  • Public/private variables (11:00)
  • Getters/setters (11:15)
  • Typing everything, ECMA typing weirdness (12:15)
  • Constructor (13:44)
  • myTrace (14:15)
  • Attaching UI components (15:00)
  • No extra listener objects! (15:30)
  • Your typical change/click handler (17:00)
  • Use public/private on your function declarations (17:35)
  • The perfect two-lines inline functions (19:00)
  • p_, m_, and k_ prefixes (21:00)
  • When to show and hide your UI elements (22:10 and again 40:00)
  • Declaring your Shared Objects (SOs) and onSync methods (23:00)

Server-side

  • What do to in onAppStart (26:00)
  • Copy and paste SO names! (26:45)
  • Setting default slots on the server-side properly (27:15)
  • Assigning unique IDs on the server-side and why (30:10)
  • onConnect and onDisconnect best practices (31:00)
  • Calling setUserID right after acceptConnection (33:40)
  • Using setUserID as your "ready-to-go" point (instead of NetConnection.Connect.Success) (34:30)
  • Client.prototype.someFunc versus client.someFunc (37:30)
  • Using SOs instead of .send() to accommodate for people who come in late (41:00)

Different multiuser sharing techniques (43:00)

  • Understanding "success" versus"change" (46:00)
  • MVC: having the server-side write to SOs (52:30)
  • Securing your SO writes (53:00)
  • Adding a tID to emulate a success (56:45)

Requirements

To complete this tutorial you will need to install the following software and files:

Tutorials and sample files:

Note: You can also find the source code within the presentation at 1:00:00.

Extending MovieClip versus extending Object

Figure 1. Extending MovieClip versus extending Object

About Macrochats

Macromedia offers live, in-depth product presentations called Macrochats—technical discussions led by product engineers, technical support engineers, and customer leaders. Macrochat content varies across all Macromedia products and technical levels.

Macrochats are recorded online utilizing Macromedia Breeze Live. There is no charge to participate. While you are viewing, please keep in mind that these presentations were delivered to a live audience.

For a list of upcoming Macrochats, view the Macrochat schedule. For a list of past Macrochats, visit the Recorded Macrochats page.

About the author

Giacomo "Peldi" Guilizzoni (aka peldi.com) is a software developer for Macromedia working on Breeze Live. He maintains a Flash Communication Server blog at peldi.com/blog/ and often writes for the Macromedia Developer Center. His grandparents do not understand a single word of this article but nonetheless think it's "neat." ;)