Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual page 144

Programming actionscript 3.0
Table of Contents

Advertisement

The traits object
The traits object, which is new in ActionScript 3.0, was implemented with performance in
mind. In previous versions of ActionScript, name lookup could be a time-consuming process
as Flash Player walked the prototype chain. In ActionScript 3.0, name lookup is much more
efficient and less time consuming because inherited properties are copied down from
superclasses into the traits object of subclasses.
The traits object is not directly accessible to programmer code, but its presence can be felt by
the improvements in performance and memory usage. The traits object provides the AVM2
with detailed information about the layout and contents of a class. With such knowledge, the
AVM2 is able to significantly reduce execution time because it can often generate direct
machine instructions to access properties or call methods directly without a time-consuming
name lookup.
Thanks to the traits object, an object's memory footprint can be significantly smaller than a
similar object in previous versions of ActionScript. For example, if a class is sealed (that is, the
class is not declared dynamic), an instance of the class does not need a hash table for
dynamically added properties, and can hold little more than a pointer to the traits objects and
some slots for the fixed properties defined in the class. As a result, an object that required 100
bytes of memory in ActionScript 2.0 could require as little as 20 bytes of memory in
ActionScript 3.0.
The traits object is an internal implementation detail and there is no guarantee that it will
not change or even disappear in future versions of ActionScript.
The prototype object
Every ActionScript class object has a property named
class's prototype object. The prototype object is a legacy of ActionScript's roots as prototype-
based language. For more information, see
The
property is read-only, which means that it cannot be modified to point to
prototype
different objects. This differs from the class
ActionScript, where the prototype could be reassigned so that it pointed to a different class.
Although the
prototype
In other words, new properties can be added to the prototype object. Properties added to the
prototype object are shared among all instances of the class.
144
Object-Oriented Programming in ActionScript
"ActionScript 1.0" on page
prototype
property is read-only, the prototype object that it references is not.
, which is a reference to the
prototype
139.
property in previous versions of

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents