This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Differences Between Flash ActionScript and Server-Side ActionScript
|
121
An excellent discussion of object-oriented programming and prototype-based inher-
itance using JavaScript is available in JavaScript: The Definitive Guide, Fourth Edition
(O’Reilly) by David Flanagan. Flanagan’s book is especially useful for server-side
scripting as it covers JavaScript 1.5—the exact same language as SSAS.
Prototype-based inheritance issues in Flash 5 and Flash MX and the various options
for implementing inheritance without using super in Flash are discussed in detail
here:
http://www.quantumwave.com/flash/inheritance.html
While the discussion centers around Flash, it is also a valuable resource for server-
side scripting.
Many of the communication objects available cannot be subclassed using these sorts
of techniques. For example, shared objects are not created by calling a constructor
function. Instead, they are created via a static method such as SharedObject.getRem-
ote( ) on the client or get( ) on the server. Often there are better ways to work with
the communication classes than inheriting from them. See Chapter 15 for more
details.
Single Execution Context
Client-side ActionScript provides a special _global object that provides a place to
store global variables that exist outside the scope of the timeline. For example:
// Assume a _global object already exists.
_global.x = 3; // OK in client-side AS; however, error in SSAS.
trace (x); // Will output: 3 in Flash MX and later.
In client-side ActionScript, if a variable is not found on the timeline and the _global
object has a property of the same name, the _global object’s property is accessed.
In SSAS there are no timelines. All server-side code executes in one global context
that is associated with each application instance. So there is little point to providing a
special
_global object. You can create an object named _global, but it will not work
as it does in client-side ActionScript. In general, you should avoid creating an object
named
_global in SSAS because it doesn’t add anything and may create problems if
you are using Flash Remoting (see Chapter 11).
When loaded into a main.asc file, the netservices.asc file creates a new
_global object
and assigns properties to it. The RecordSet.asc file also adds properties to the
_global
object. Furthermore, netservices.asc adds the unshift( ) and registerClass( ) methods to
the Object class; since all classes inherit from Object, every object shows these meth-
ods when its properties are enumerated with a for-in loop. Chapter 11 contains addi-
tional information on dealing with these inconveniences. If you must use a
_global
object in SSAS, you should check whether it already exists before creating your own
and be careful to avoid collisions with the
_global properties defined in netservices.asc.

Get Programming Flash Communication Server now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.