RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Extending Flash MX 2004, Part 1: Understanding the JSFL DOM

The key to learning to write your own Flash extensions is to understand the Flash DOM and thus the first article in this series will explain the DOM in detail.

SFL is based around a Document Object Model (DOM) that exposes a hierarchy of Objects, which represent the structure of a Flash document in the form of a hierarchical tree, very similar in nature to a family tree. Each object allows you to dynamically access and update the structure of a Flash document. The key to learning to write your own Flash extensions is to understand the Flash DOM and thus the first article in this series will explain the DOM in detail.

Types of Flash Documents
Flash MX 2004, works with two types of documents, the first is the standard timeline-based document that users of previous versions of Flash are familiar with and the second is screen-based documents, which are new in Flash MX 2004. Screen-based documents use a different metaphor for organizing your movies and you will know them as Form Applications and Slide Presentations.

The DOM of a screen-based document differs slightly from that of a timeline-based document but because timeline-based documents are far more common, I will only cover their DOM in this article.

Anatomy of a Flash Document
To begin with, I want you to think about each of the different parts of a Flash document. Flash documents are made up of:
  • Timelines
  • Layers
  • Frames
  • Symbols
  • Shapes
  • Textfields
  • Library
Different types of symbols are stored in the library:
  • Movieclips
  • Buttons
  • Graphics
  • Bitmaps
  • Sounds
  • Videos
  • Components
Timeline-based documents have a library and one or more timelines (Scenes). Movieclips, buttons, components, and graphics have their own timelines. Timelines contain layers, layers contain frames, and key frames contain instances of symbols from the library, shapes, and textfields.

Author Note: It is important to realize that Flash works with groups of frames (not individual frames). A group of frames begins with one keyframe and ends at the frame before the next keyframe on that layer or the last frame in that layer, whichever is first. Each frame in a group of frames refers to the first frame in the group (the originating keyframe).

The Flash DOM represents this hierarchy and each of those separate elements of a Flash document in the form of objects. So there is a unique object for each layer in a Flash document and there is also a unique object for every frame in a Flash document, etc.

These objects have properties that describe that particular element; so for example all layer objects have a 'name' property that contains the name of that particular layer:
Figure 1. Timeline: A Flash timeline object with one layer is shown.
Figure 1 shows a timeline, which contains one layer, this layer has a name of 'Layer Name'. So in JSFL, we can access the name of that particular layer, using:
Each separate type of object may also have associated methods, which manipulate that particular object in its visual form in the Flash IDE; so for example, all timeline objects have a method called 'deleteLayer' that removes a particular layer from that particular timeline. So in JSFL, we can get Flash to delete the first layer of a timeline using:

Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date