Flash Physiology

The Flash Physiology

Introduction to the Flash Physiology

The Flash Physiology studies the behavior of the Flash Player through observation of form and experimentation with function. The Physiology begins where the documentation ends and provides example code and exploratory projects to probe into the behavior and performance of the Flash Player.

Abstract Flash player base classes

Some of the core classes in the Flash player are actually abstract classes. Even though you cannot instantiate these classes directly, they are still very important to understand. These classes are the parent classes for all of the visual display classes in Flash and they contribute functionality to the concrete classes that you will use in your application.

DisplayObject Flash Class

The DisplayObject class is the parent class for all visual components in the Flash player. Every class that can render to the Stage inherits from DisplayObject. Common subclasses of DisplayObject that you may be familiar with include Sprite, Shape, Bitmap, and MovieClip.

The DisplayObject, however, does not contain any methods for rendering data on screen. These methods are added by subclasses. For example, the Sprite and Shape classes support the graphics:Graphics property which supports the Flash drawing API. However, Bitmap, TextField, and StaticText do not support the drawing API and instead directly render images or text.

DisplayObject inherits from EventDispatcher because every DisplayObject participates in the event loop of the Flash player.

InteractiveObject Flash abstract class

The InteractiveObject class is a core class in Flash player. InteractiveObject is an abstract base class so you cannot create instances of it. Also, you cannot subclass it yourself because it is not a complete class. InteractiveObject is a subclass of DisplayObject and adds support for interacting with the user of the Flash application. Flash classes which are not subclasses of InteractiveObject, such as Shape and StaticText, do not respond to mouse or keyboard actions.

Display classes can only interact with user events if they are currently on the Flash display list. Classes are placed on the display list through the addChild(obj:DisplayObject) method on DisplayObjectContainer. For your class to support the interactivity described below, please ensure that it is on the display list. You can check the stage property to see if the object is in the display list. See the articles on the display list and DisplayObject for more information.

InteractiveObject supports the contextMenu:NativeMenu property. You can use this to specify a ContextMenu or a NativeMenu. NativeMenu is only supported by the AIR runtime, not the Flash player. If you assign a custom ContextMenu to the InteractiveObject it will be displayed when the user right-clicks on the object.

You can enable or disable support for different kinds of user interaction on InteractiveObject using the doubleClickEnabled, mouseEnabled, and tabEnabled properties. These properties can be the source of some consternation, particularly the doubleClickEnabled property which defaults to false. This means that typical components will not receive the doubleClick event.

Setting tabEnabled will allow users to use keyboard navigation to reach the component in the tab order. This property is false by default except for SimpleButtons, TextFields with type="input", and Sprites and MovieClips with buttonMode=true. Setting tabIndex to anything other than -1 will disable the automatic tab ordering for the entire Flash player.

Core Flash Player Classes

Shape Flash class

The Shape class is the most basic Flash class that supports rendering through the graphics property. The Shape hierarchy is: Shape < DisplayObject.

Sprite Flash class

The Sprite class is one of the most basic rendering classes available in Flash. It supports the Flash drawing API, can contain other DisplayObjects, and supports user interaction events. Sprite does not have a timeline like MovieClip which makes it smaller and faster if you are not running timeline-based animations. The Sprite class is the base class which most UI components inherit from such as the UIComponent in Flex.

The only class which is simpler than Sprite which supports the Flash drawing API is the Shape class. The difference is that Shape is not a DisplayObjectContainer or an InteractiveObject so it cannot have children and it does not support user interaction.

Its Flash class hierarchy is Sprite < DisplayObjectContainer < InteractiveObject < DisplayObject. Each of these classes serves a specific purpose and relevant information can be found in their sections.

More to come...

Stage Flash Class

The Stage class is the area in the Flash player that all of the content is rendered into. The Stage is the root of the display list. Other components will be rendered in the normal render loop only if they are children or descendants of the Stage class.

Stage is a DisplayObjectContainer class and supports the normal methods of addChild(child:DisplayObject) and removeChild(child:DisplayObject). Outside of these methods, however, many of the properties of DisplayObject to not apply to the Stage since it has no rendering by itself.

You can access the Stage from any component that is part of the display list hierarchy. When a class is added to the display list it will receive the addedToStage event and thereafter its stage property will reference the Stage it has been added to.

TextField Flash class

The TextField class is one of the most basic classes in Flash for dealing with text. The TextField class is designed for dynamic and potentially interactive text. The text can be selectable or not and it supports multiline text and text formatting using basic HTML and CSS. Its inheritance is TextField < InteractiveObject < DisplayObject.

The TextField class is the basis for most of the text manipulation that is performed in Flash or Flex. If you are working in the Flash authoring environment you can also create StaticText objects but these are hard-coded and cannot have their text updated at runtime nor can they interact with user operations.

The TextField class is a special purpose class that is designed only to work with text. It does not support the graphics property so you cannot render into it. Also, because it is not a DisplayObjectContainer you cannot add child objects to it. For this reason, subclasses of TextField are very limited in what they can do. Keep this in mind when examining the inheritance hierarchy of your class. Flex classes such as UITextField, DataGridItemRenderer, and AdvancedDataGridItemRenderer share these limitations.

Flash Display List

The display list is the mechanism that Flash uses to render itself onto the users screen. The display list is rooted in the Stage class and consists of all of its descendants (children, grandchildren, and so forth). DisplayObjects on the display list have a specific rendering lifecycle and event propagation mechanism. Objects which are not on the display list will not be rendered and cannot interact with user events.

More to come...

Flash Events

Flash dispatches certain standard events based on the interactions of components, especially with regards to rendering and the display list. Generally, a component receives added and addedToStage, then render events. When the component is removed it will usually receive removed and removedFromStage. Obviously, if the component is only added to another component, and the parent component is not yet on the Stage, then the "Stage" events won't fire until the topmost parent is added to the Stage.

Flash Event "added" (Event.ADDED)

The added event is fired when a component is added as a child to another component. This is accomplished through the addChild(child:DisplayObject) method (or addChildAt(child:DisplayObject,pos:int)).

When the component is removed, it will receive the removed event. This is the complementary event to added.

Flash Event "addedToStage" (Event.ADDED_TO_STAGE)

The addedToStage event fires when a component becomes part of the display list. The display list is rooted in the Stage component and contains all of its descendants. When your component is on the Stage it participates in the standard render loop and the event dispatching loop.

Keep in mind that even though your component is not in the display list, it can still be asked to render itself using the draw method of BitmapData.

Flash Event "removed" (Event.REMOVED)

The removed event is fired when a component is removed from its current parent. This is accomplished with the removeChild(child:DisplayObject) method (or removeChildAt(index:int)).

If the component was previously on the Stage, then the removedFromStage event will also be dispatched to the component.

Flash Event "removedFromStage" (Event.REMOVED_FROM_STAGE)

The removedFromStage event is dispatched to a component when it is removed from its parent. If the parent component was on the display list of the Stage, then the removedFromStage event will be dispatched to the component along with the removed event.

A component which is not on the display list of the Stage (if it is not a child or descendant of the Stage) does not participate in the render loop or the event dispatching loop of the Flash player. Such a component is effectively idle until it is added to the stage again. However, the component could still be rendered into a BitmapData object using the draw method.

Flash drawing API

The Flash drawing API is the primary mechanism for rendering interactive graphics outside of the Flash editing environment. The drawing API is a low-level interface that draws primitives such as lines, curves, and triangles (in Flash 10). It can style those primitives with line styles and fill styles that get their content from vector gradients or bitmaps.

The drawing API is made available to objects on the display list through the graphics property.

More to come...