Download full Extending Macromedia Flash MX 2004 Complete Guide and Reference to JavaScript Flash 1st Edition Keith Peters ebook all chapters
Download full Extending Macromedia Flash MX 2004 Complete Guide and Reference to JavaScript Flash 1st Edition Keith Peters ebook all chapters
com
https://ebookname.com/product/extending-macromedia-flash-
mx-2004-complete-guide-and-reference-to-javascript-
flash-1st-edition-keith-peters/
OR CLICK BUTTON
DOWNLOAD EBOOK
https://ebookname.com/product/complete-flash-remoting-mx-1st-edition-
joey-lott/
ebookname.com
https://ebookname.com/product/flash-after-effects-second-edition-add-
broadcast-features-to-your-flash-designs-chris-jackson/
ebookname.com
https://ebookname.com/product/macromedia-dreamweaver-mx-fast-easy-web-
development-1st-edition-aneesha-bakharia/
ebookname.com
https://ebookname.com/product/cities-of-the-world-africa-6th-edition/
ebookname.com
https://ebookname.com/product/the-end-of-separation-gautam-sachdeva/
ebookname.com
https://ebookname.com/product/vaccines-for-biodefense-and-emerging-
and-neglected-diseases-1st-edition-alan-d-t-barrett/
ebookname.com
https://ebookname.com/product/tumor-diagnosis-practical-approach-and-
pattern-analysis-2nd-edition-awatif-al-nafussi/
ebookname.com
https://ebookname.com/product/introducing-statistics-2nd-ed-edition-
upton/
ebookname.com
Strategic Business Development for Information Centres and
Libraries 1st Edition Margareta Nelke (Auth.)
https://ebookname.com/product/strategic-business-development-for-
information-centres-and-libraries-1st-edition-margareta-nelke-auth/
ebookname.com
Extending Macromedia
Flash MX 2004
Complete Guide and Reference
to JavaScript Flash
Keith Peters
Todd Yard
www.springeronline.com.
For information on translations, please e-mail [email protected] or visit www.apress.com.
Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use. eBook
versions and licenses are also available for most titles. For more information, reference our Special Bulk
Sales-eBook Licensing web page at www.apress.com/bulk-sales.
The information in this book is distributed on an "as is" basis, without warranty. Although every precaution has been
taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity
with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained
in this work.
The source code for this book is freely available to readers at www.friendsofed.comin the Downloads section.
Credits
President and Publisher: Copy Editor:
Paul Manning Ami Knox
Lead Editor: Compositor:
Ben Renow-Clarke Dina Quan
Technical Reviewers: Proof Reader:
Peter Elst Linda Seifert
Editorial Board: Indexer:
Steve Anglin, Mark Beckner, Ewan Buckingham, Michael Brinkman
Gary Cornell, Jonathan Gennick, Jonathan Hassell,
Michelle Lowman, James Markham, Matthew Cover Image Artist:
Moodie, Jeff Olson, Jeffrey Pepper, Frank Corne van Dooren
Pohlmann, Douglas Pundick, Ben Renow-Clarke, Cover Designer:
Dominic Shakeshaft, Matt Wade, Tom Welsh Anna Ishchenko
Coordinating Editor:
Tracy Brown Collins
CONTENTS AT A GLANCE
Foreword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi
Acknowledgments • . . . . . • • • • • . . . . . . • • • • • . . . xvii
Chapter 5: XM L to UI . . . . • • • • • . . . . . . • • • • • 163
Index . . . . .• . . . . . . . . . . 437
ii i
CONTENTS
Foreword . . . . . . . xi
Acknowledgments . . . . . . . . . . . . . . . . xvii
v
CONTENTS
friends of ED Forums · . . . . . . . . . . . . . . . . 16
Styles Used in This Book . 16
vi
CONTENTS
vii
CONTENTS
viii
CONTENTS
Document .. 301
DrawingLayer . 333
Edge .. . 336
Effect . . . . . 338
Element . . . . 339
EmbeddedVideolnstance 343
Fill . . . . . 343
Flash . . . . 345
Folderltem 353
Fontltem 353
Frame .. 353
Half Edge 358
Instance. 359
Item .. 360
Layer .. 363
Library .. 365
LinkedVideolnstance . 372
Math ... . 372
Matrix ... . 373
OutputPanel 375
Parameter. 376
Path . . . . . 378
Screen ... . 380
ScreenOutline 383
ScreenType 386
Shape ... 388
Soundltem 390
Stroke ... 391
Symbollnstance 396
Symbolltem. · 401
Text . . . · 403
TextAttrs · 410
TextRun . .413
Timeline. · 414
Tool Functions · 424
ToolObj · 426
Tools .. . · 429
Vertex .. . · 432
Videoltem · 433
XMLUI ... · 433
Index . . . . . . 437
ix
FOREWORD
If I were to tell you that the latest version of Flash can and will increase your productivity lev-
els by speeding up the development process and eradicating all those tedious, repetitive
tasks that you waste valuable development time on, over and over again, I would imagine
that you would be interested in hearing a little more about it. If you find yourself craving the
lowdown on these new and exciting capabilities, then you have opened the right book.
How long does it take for you to add a stop action to each of one or more frames in a time-
line? Or how long does it take for you to convert a few graphic symbols into movie clip sym-
bols? There isn't really a definitive answer, but what I am getting at is that it takes too long,
or longer than it should. It is boring and nobody enjoys doing it, but developers all do it reg-
ularly without even thinking about it-these are the mundane and repetitive tasks that you
often encounter when building any Flash movie. These activities and many more account for
a lot of the time you spend developing or designing; you don't spend enough time doing the
kind of work you enjoy.
The key feature that sold Macromedia Flash MX 2004 to me and my employer has to be the
fact that by utilizing the new extensibility layer in Flash MX 2004 it is possible to build or
record macro-like scripts that will perform a particular sequence of interactions-a task. You
can then play back this task, at a later date with the click of a button, to automatically repeat
that sequence of interactions. But that's not all you can do; we've barely scratched the
surface ...
In the relatively short time I have had Flash MX 2004, it has allowed me to reduce the
amount of time I spend doing the boring, tedious stuff in my day-to-day work, and increase
the amount of time I have to work on the more interesting and challenging tasks.
Recently, my company was developing an interactive world map for one of our clients. They
wanted users to be able to roll over each country and have its name appear in a tooltip. They
provided us with a vector world map, so we imported it into Flash, and split each country
onto a separate layer, giving the layer the name of the country.
We then wrote a command that would go through this Flash movie, select the shape on each
layer, convert it into a button, and add a rollover state to that button, which simply changed
the color of the country. The command then added a little bit of ActionScript to activate the
tooltip and display the name of the country on rollover.
xi
FOREWORD
With Flash MX 2004, we were then able run this command on the entire project, and
within five minutes our world map was finished, leaving me free to start work on my next
project, get a haircut, walk the dog, wash the car, and build a sandcastle! Can you imagine
how much longer it would have taken to do this manually? Not to mention how boring it
would have been to select each of the 192 countries and convert them all into buttons,
adding a rollover state and the required ActionScript to each one. It'd probably easily take
the best part of a full working day!
As if this weren't enough to get excited about, there's more. If you put what you learn
from this book into practice, and develop an extension that you feel can be utilized by
your peers, then you now, as a Flash developer, have a new commercial avenue-packag-
ing an extension and selling it to the world. I have jumped on this opportunity and plan to
release a Flash extension that adds auto-saving capabilities to Flash MX 2004 in the very
near future. Developing this extension was a breeze using the new scripting language and
other enhancements that the new extensibility layer provides. There is nothing stopping
you doing the same.
This book will take you, step by step, through each of the various types of Flash exten-
sions-Timeline Effects, commands, custom tools, and Flash panels, giving you all the gory
details in a clear and jargon-free manner. Starting off with the basics and steadily working
up to the more complex tools and techniques, Extending Flash MX 2004: Complete Guide
and Reference to javaScript Flash is loaded with practical examples and code snippets to
help you along the way. And the latter part of the book consists of a complete reference
to the JavaScript API, which you can rely on when you head off and start to build and dis-
tribute your own Flash extensions.
www.flashguru.co.uk
xii
ABOUT THE AUTHORS
Keith Peters lives in the vicinity of Boston, MA, in the USA with his
wife, Kazumi, and their new daughter, Kristine. He has been work-
ing with Flash since 1999, and has coauthored many books for
friends of ED, including Macromedia Flash MX Studio, Flash MX
Most Wanted: Effects and Movies, and the ground breaking Flash
Math Creativity. In 2001, Keith started the experimental Flash site
www.bit-l01.COm, on which he regularly posts new cutting-edge,
open source experiments. The site recently won an award at the
Flashforward 2003 Flash Film Festival in the Experimental category.
In addition to the experiments on the site, there are several highly
regarded Flash tutorials that have been translated into many languages and are now posted
on web sites throughout the world. Keith is currently working full time doing Flash develop-
ment and various writing projects.
xiii
ABOUT THE TECHNICAL REVIEWER
xiv
ABOUT THE COVER IMAGE
Corne van Dooren designed the front cover image for this book.
After a typically vague editorial brief along the lines of: "Make us
something cool and space-age, with architecture and the Earth,"
Corne was inspired to extend the cover of the companion title
Flash MX Designer's ActionScript Reference (also from friends of ED),
and take it in a different direction suitable for this new Flash
Extensibility technology. With a colorful background as an avid
cartoonist, Corne discovered the infinite world of multimedia at the
age of 17-a journey of discovery that hasn't stopped since. Corne
spends much of his time with most of the well-known packages
from Adobe and Macromedia, for both online and offline use. His mantra has always been
"The only limit to multimedia is the imagination." You can see more of his work and contact
him at www.comevandooren.com. and be sure to check out his chapter in the upcoming
New Masters of Photoshop: Volume 2 from friends of ED.
xv
ACKNOWLEDGMENTS
There are a number of people whose help or advice was invaluable in the writing of this
book. First, there's Steve Rycroft, to whom we originally presented the idea of this book last
summer. He's been there almost daily, guiding, prodding, and pushing the project through to
the end. Peter Brouwers provided some valuable early documentation of the JavaScript API.
Without Robin Debreuil, we're sure we would never have figured out the fill matrix, and
much of the code describing it is directly from his description of it. Sharon Selden from
Macromedia was always helpful in answering questions or finding the answers, and continues
to do so over in the forums at www.flashextensibility.com. Finally, Peter Elst gave an
incredibly thorough technical review of each page of the book, including each line of the ref-
erence section, a job we can only imagine as tedious-so special thanks to Peter!
xvii
1 INTRODUCTION TO FLASH
EXTENSIBILITY
Re Edit
• layer I :Frame I
Tools
Data
~~ Embedded Video ~
Pause
bitmap test / ~. PIey
Detect Accessibility (I A Show
cIom chart tests
FlashJavaScriptHelp o D.
Stop
frame test /
flJ~
EXTENDING MACROMEDIA FLASH MX 2004
Welcome to Extending Flash MX 2004! This book combines a rich introduction and tutorial
guide to all of the exciting new extensibility features of Macromedia Flash MX 2004, along
with a comprehensive reference dictionary cataloging all of the associated extensibility
technologies and language syntax. Our aim has been to make this book the best resource
to Flash extensibility available-the book that you'll keep on your desk and never
exhaust-complete with the most in-depth coverage possible to enhance your under-
standing and plenty of practical examples to inspire your creativity.
The extensibility architecture, introduced in Flash MX 2004, is one of the most powerful
enhancements to the authoring environment ever seen. As such, it's probably a good idea
to take a look at exactly what we mean by extensibility-what it can do, what it can't
do-and dive in with a few examples to get your feet wet.
We should mention here that everything we'll cover in this book applies to both
Flash MX 2004 and Flash MX Professional 2004. The main difference is that the
Professional version comes with a built-in script editor with which you can cre-
ate your extensibility scripts. That's certainly a nice bonus for users of this ver-
sion, but users of the standard version needn't worry-these scripts are created
in plain text, so you can use any text editor you like to do the same thing.
Personally, when we first heard the term, we initially associated it, incorrectly as you'll see,
with concepts and buzzwords like accessibility and usability. All well and good, but not too
exciting. Since many new features are available in Flash MX 2004, it's easy to overlook
extensibility as some other minor enhancement that you mayor may not need someday.
But when we're discussing the extensibility architecture, we're literally talking about the
ability to extend the authoring environment in Flash. And this doesn't only mean that Flash
MX 2004 is just extended beyond Flash MX-that much is obvious. What we're talking
about is you, the Flash user, being able to extend Flash MX 2004 to make it do things that
it couldn't do when you installed it. For example, you can add new drawing tools to the
toolbar to create any kind of shape or drawing imaginable, including some basic real-time
3D effects. In fact, we'll show you how to do just that in Chapter 3! You can create com-
mands that perform complex, time-consuming tasks instantly. These can be simple macro-
type commands or full programs that create new Flash documents, add content to them,
and publish them. Most of these enhancements make use of a new scripting language
called JavaScript Flash, or JSFL, which can be used to manipulate the authoring environ-
ment and its various elements. We'll present on overview of JSFL shortly, and you'll be get-
ting very familiar with the practical side of JSFL starting in Chapter 2.
1. Commands 4. Behaviors
2. Tools 5. Advanced tools
3. Timeline Effects
2
INTRODUCTION TO FLASH EXTENSIBILITY
Commands
If you take a look at the Flash MX 2004 authoring environment,
you'll see a menu item that wasn't there in previous versions of
Flash-Commands-as shown in Figure 1-1.
In Flash MX 2004, you can create new custom commands that can
be run from this menu. In Figure 1-1, you can tell that we've
already been going crazy with our own custom commands; if you
Commands Control
Circle Text
Detect Accossililly
getConflQDir
Moyle Explorer
wndow He
Manage ~ved Conmands, , ,
Get More Conmands .. ,
-
Process PDF page by page
haven't yet played around with this feature, your menu is likely to
Reload Effects
read No Commands Found at the moment. Not to worry though, Reload Tools
you'll soon be brimming with ideas for new commands! runscript test
Figure 1-1.
Selection to Grid
starBurst The Commands menu
The commands functionality of Flash MX 2004 is probably the W~ve Text
simplest level of Flash extensibility to get started with, as it
doesn't really require any technical know-how about the extensi-
bility framework at all. If you've ever recorded a macro in other popular programs, this can
be just as simple-you perform the actions you want and then save them as a command.
Anytime you need to perform those actions again, simply select that command from the
Commands menu, and those actions will be replayed.
But don't take that to mean your commands need to be simple. You can record almost any
number of actions into a command, and you can then go in and edit the resulting file to
customize it even further. As you become more confident, you can even create your own
commands from scratch, as simply as writing a script. Since these commands are merely
text files, you can easily share these with others in your work group, or if you create a par-
ticularly useful one, distribute it to whoever might find it handy. We're sure you'll soon be
able to download any number of commands from various open source repositories.
A key resource, and perhaps the first one online, is the companion website to
this book, www.flashextensibility.com. There you'll find all the commands
discussed in this book, as well as all of the other files created here. In addition,
visitors will be able to upload their own commands and share ideas and tech-
niques. This site will soon consist of a library of hundreds of useful extensibility
tools for you to use or study as examples.
TooLs
No doubt you're pretty familiar with the trusty toolbar in Flash, shown in Figure 1-2.
You've got your selection tools, your drawing tools, eyedropper, eraser, etc., all there, right
where you need them. Right where they've always been, like they're carved in stone. Well
say goodbye to that concept. In Flash MX 2004, you can not only rearrange the existing
tools however you like, but also add any number of new tools, created in the same way
you would code a custom command.
3
EXTENDING MACROMEDIA FLASH MX 2004
rook Tools are quite a bit more complex than commands, though. Although a com-
mand is generally a linear script that performs a series of actions and then ends,
tools become activated when selected and deactivated when another tool is
selected. While active, they are basically little programs running in the author-
ing environment, responding to various actions in a fully event-driven frame-
work.
The most common use for tools is in creating custom drawing shapes. Up to
Flash MX, we had a Line, Oval, Rectangle, and freehand drawing tools to draw
with. Now with Flash MX 2004 extensibility, any shape or form that can be math-
Figure 1-2. ematically or programmatically defined can be inserted right into the toolbar.
View
The Flash toolbar
~ 0. Macromedia has provided one new tool in this version of Flash, the PolyStar
tool, which was created with the new extensibility architecture. You can find it
on your toolbar right under the Rectangle tool. Just click and hold over the rectangle icon
and the PolyStar tool will slide out. We can imagine that before long, libraries of stars,
arrows, callouts, smiley faces, and lightning bolts will be circulating the Web, begging to be
plugged into your toolbar. In fact, you'll beat them to the punch when we demonstrate
how to create a couple of custom-built tools in Chapter 3.
TimeLine Effects
Face it: The first thing you likely did when you started using Flash was create a tween.
Following some book or tutorial, you put a shape on frame one, added some frames, cre-
ated a tween, made another keyframe, and changed the shape somehow. You probably
also remember, at some later point, digging into the advanced tutorials, trying to create
some really cool effect, struggling along trying to follow precisely what the author was say-
ing, and most likely making far too many mistakes before you either got it right or gave up.
Wouldn't it be nice if instead the author could have just recorded the actions you needed
to take, and you could just supply your symbol and say, "Yeah, do that to this!"
That's essentially what Timeline Effects are: prescripted tweens. You supply the symbol
and let the effect do its magic on it. These can even include user interfaces based on
Shockwave Flash (SWF), where you can tweak various parameters and preview the effect.
For a quick example of this, draw something onstage, a simple ellipse say, and right-click it
(CMD-click for Mac). From the context menu, choose Timeline Effects> Effects> Blur
(you can also get to this option via the Insert menu), and a panel opens up with the effect
interface created in Flash as you see in Figure 1-3-in fact, this is a SWF itself.
4
INTRODUCTION TO FLASH EXTENSIBILITY
-
BLUR
Et1«1 Duration 16
RftOIUUOI'I 15
Sale O.H
OK ao_
Set up some parameters and click OK and test your movie. Admittedly not a hugely excit-
ing effect, but it shows off Flash's ability to create reasonably complex tweens at the click
of a button.
Once again, you're going to see a ton of these circulating around. From a creative stand-
point, we should advise you to use them with caution: A visitor to your site seeing the
same canned Timeline Effect they've seen on ten other websites isn't going to be very
impressed. With that in mind though, Timeline Effects can be a huge timesaver, particularly
if you know how to create effects of your own, which is exactly what is covered in detail in
Chapter 4. And don't forget to visit our website, www.flashextensibility.com. to check
out some of the cool effects available for download.
Behaviors
Behaviors are like a distant cousin to Timeline Effects. Rather than a pre-scripted tween,
here we're talking about a pre-scripted script. The simpler behaviors are largely going to
be for the designer who wants an object to have a certain behavior that can only be
scripted, but doesn't want to go through the trouble of learning ActionScript.
For another quick demo, create a movie clip on the stage and select it. Open the Behaviors
panel (Windows> Development Panels> Behaviors or SHIFT+F3) and click the plus sym-
bol. A context-sensitive list of potential behaviors occurs. Choose Start Dragging Movieclip
as shown in Figure 1-4.
5
EXTENDING MACROMEDIA FLASH MX 2004
-
... ~ l?~
~.='::=:2~
.~
6rftDForW41d
PrO)!ICtOf • Brno to Front
_ • 0\0>I<~_
wl!lb • GotoMdPla:fatframeorlab@l
G0t04ll'ldstop«fral'flecrlabel
load _ _
load"'_
Send_d
S!ndto Bad:.
Figure 1-4.
The Behaviors panel and associated options
You can also choose an event that will trigger the behavior, so set it as On Press. Test your
movie (CTRLICMO+ENTER) and click the movie clip. It should start dragging (following the
mouse). Of course, you'll probably also want to add a Stop Dragging Movieclip command
for On Release. All of this dragging and responding to mouse events is obviously done
behind the scenes with ActionScript, but you didn't have to write (or know) a single line
of code.
Multiple behaviors can be applied to the same object, based on the same or different
events, so some complex behaviors can be created through such "layering."
In this book we'll be demonstrating how to create behaviors, and we don't insist anywhere
that your behaviors be as simple as Start Dragging. Virtually any code you can write into an
event handler in ActionScript can be turned into a custom behavior. It goes without saying
that there will be plenty of these behaviors available at www.flashextensibility.com.
Advanced Tools
Finally, if all the features you've seen so far don't get some wild ideas going in your head
about what you can do, we've come to the section of items we'll lump together generally
as advanced tools. These mainly consist of a little command called MMExecute and
another tool that is used at the command line.
You can encode that into a string and store it in a variable like so:
6
INTRODUCTION TO FLASH EXTENSIBILITY
-
Then, you could use that string inside MMExecute to run that jSFL program:
MMExecute(thejSFL) ;
Don't worry if you don't follow this code yet-all will be revealed later in this book.
Essentially, this means that you can not only extend Flash through a menu, toolbar, and the
special timeline and behaviors functions, but also automatically run one of these extensi-
bility scripts from a SWF running in the authoring environment. That last phrase is impor-
tant; the extensibility tools only have power from within the authoring environment. Thus,
MMExecute must be contained in a SWF running in the authoring environment, such as a
live preview or custom UI SWF, for it to have any effect at all. The jSFL code that is run
affects the document that is open in the authoring environment. It does nothing at all to
the SWF that contains the MMExecute command.
This makes a whole bunch of things possible in the field of component creation. Flash MX
2004 components contain live previews, which are SWFs that can contain MMExecute state-
ments. In this way, once a component is added to a document, it can take certain actions
on that document such as adding or modifying content.
Lastly is the fact that these scripts can now be run from the command line, or even by
double-clicking the icon for a script. This will automatically open up Flash and perform any
actions you want, including creating documents, exporting SWF, and so on. This opens up
almost the entire Flash authoring application programming interface (API) to be run from
a command line, via an extensibility script. While this allows for batch processing or even
creation of Flash movies, you can also envision a program operating outside of Flash, feed-
ing scripts to the command-line tool. This could mean a whole new Flash UI! Another con-
cept is using Flash on a web server, where a web page calls a PHP or ASP script, creating a
script for Flash, and then runs that script, creating a brand new SWF on the server, which
is then fed back to the calling web page.
For example, certain extensibility commands enable you to create new movie clips and
insert graphic content into them. These would be called from a command, tool, or
Timeline Effect, or perhaps from a SWF running as a custom UI; but in any case, they
would be called from within the authoring environment. In a final exported SWF, the only
way to create a movie clip is the ActionScript function createEmptyMovieClip, which
remains unchanged since Flash MX. To add new graphics to it, you might use the
ActionScript drawing API, as in Flash MX.
7
EXTENDING MACROMEDIA FLASH MX 2004
Also available are extensibility commands to change the stage size or color or even change
the frame rate of a movie. This is only in the course of authoring a movie. There is still no
way to directly perform these actions from within a published SWF (though you still have
plenty of ways to fake it, of course!).
This mostly gets confusing when running the MMExecute function. When you have some
ActionScript in a movie with a line like setFPS(30), it's easy to get excited about how you
can now control the frame rate of a movie. We just want to save you the disappointment
later when you realize it doesn't work exactly like that.
JSFL-JavaScript Flash
The simple fact is that these extensibility scripts, which we've so vaguely been referring to
up to now, are written in javaScript. Why javaScript, you ask, when all the rest of Flash is
based on ActionScript? Well, that's a question for the engineers who designed it all, and
they probably had very good reasons. The good news, though, is that both javaScript and
ActionScript are based on the same standard, ECMA. So, if you have more than a raw
beginner's experience in ActionScript, you should feel quite at home with jSFL.
As mentioned, a jSFL file is a simple text file containing a script. You can create a jSFL file
with any text editor, or you can use the built-in editor in Flash MX Professional 2004. If you
are using the Professional version, you'll have the advantage of syntax highlighting, code
hinting and completion in the editor. This is a very useful feature, especially when you're
8
INTRODUCTION TO FLASH EXTENSIBILITY
still learning jSFL. However, many fine external code editors are available out there that
-
can be configured to do the same thing. A popular one among Flash developers is
SciteFlash, available free for download at www.bomberstudios.com/sciteflash/. This
already has code completion and highlighting for ActionScript, and it will only be a matter
of time before configuration files are created for jSFL as well. In fact, SciteFlash has several
useful features not available in the built-in editor, such as code folding, through which you
can collapse a function or code block into a single line. With all due respect to the good
folks at Macromedia, it wouldn't surprise us if many Flash Pro users continue to use this
fine external editor.
Although the syntax of the script you create for your extensibility tools will be that of
javaScript, a large number of new objects, properties, and methods relate directly to Flash.
It's these objects and methods that are collectively known as the javaScript API. In hand
coding your new extensions, you'll be dealing with these new methods and properties for
the largest share of functionality of your script. Toward the end of this book you'll find a
comprehensive reference dictionary to all of these objects, methods, and properties.
The DOM
The Document Object Model (DaM) is the model of choice for all the objects in a Flash
document. If you've ever programmed in javaScript, this will be a familiar concept to you.
The DaM for a web page is a way of representing everything on the page as an object that
can be manipulated in a javaScript program. Thus, you have predefined objects for the
document itself, for each element in it, and even for such things as the browser and the
screen. Each of these objects has properties and perhaps methods that can be applied to
change the appearance or behavior of that particular element, or to manipulate and pres-
ent data within it. For example, in a browser, the document object refers to the HTML doc-
ument being displayed in the browser. This object has various methods and properties. An
example of one of its methods is write. Anything given to this method as a parameter will
be written into the document. You can test this directly by typing the following into the
address bar of your browser:
javascript:document.write("Hello browser")
Press ENTER and the message will be written to the browser window. An example of a doc-
ument property is bgColor, with which you can read or set the background color of the
current document. Enter this into your browser to see it at work:
javascript:document.bgColor=Oxff44bb;document.write("Hello browser!")
Similarly, jSFL has a Document Object Model that represents virtually every aspect of a
Flash movie in the authoring environment, a portion of which you can see in Figure 1-5.
Actually, the DaM encompasses the full authoring environment itself, any documents in it,
and several of the panels you see and use.
9
EXTENDING MACROMEDIA FLASH MX 2004
flash
documents - - - - - - - - - - - r - currentTimeline
tools - - - - - . - mouseIsDown time lines -----r- name
componentsPanel al tIsDown library
effects layers
activeEffect shiftIsDown livePreview
configDirectory ctlIsDown width currentFrame
screenTypes height
xmlui toolObjs backgroundColor frameCount
viewMatrix activeTool frameRate
Math selection currentLayer
penLoc
ou t pu tP ane 1 name
configURI penDownLoc screenOutline layerCount
version
drawing Layer accName
description
silent
forceSimple
auto Label
publish Profiles
current Publish Profile
Figure 1-5. Tree diagram showing just a few sections of the Flash DOM
We'll get into this in a lot more detail later, but to give you a rough idea of it, the base-
level object in the DOM is the flash object, which can also be accessed as fl. One of the
key properties of fl is documents, which is an array containing all the documents cur-
rently opened in Flash (see Figure 1-6). Thus, you can access the first document in the
authoring environment with the expression fl. documents [0]. Likewise, you can access the
currently active document at any time with fl.getDocumentDOMO.
Window ~
New Window Ctn+Alt+K Figure 1-6.
Toooba<s , Here you can see multiple documents open in Flash. Each
Project Shift+F8
document is an element in the fl. documents array.
\I Properties Ctrl+F3
Sa_
" Tmelne Ctrl+Alt+T
" Tools Ctrl+F2
Llxary FlI
, A document object most importantly contains a timeline
Design p",,-ds
, object, which is accessed through the document method
De"iopment p",,-ds
Other P....... , getTimeLineO. Once you have a reference to the timeline,
you can get access to the various layers of the timeline
HIde P.......
Pone! Sets
F~
, through a property called, obviously enough, layers. Again,
S."P...... L~ ... this is an array, with each element representing a layer in the
COS<o timeline.
Til.
'" 1 Unttied-I You're probably getting a clearer idea of this now, and may
2 GIld Tcd.jsII
3r~.fIa*
have even guessed that frames is a property of each layer-it's
4030130.fIa' an array containing all the frames in that layer.
Finally, you have the elements property of each frame. This is an array containing each
object in that frame, whether it's a button, movie clip, graphic, or simple shape, as shown
in Figure 1-7.
10
Random documents with unrelated
content Scribd suggests to you:
The Project Gutenberg eBook of A voyage
round the world
This ebook is for the use of anyone anywhere in the United
States and most other parts of the world at no cost and with
almost no restrictions whatsoever. You may copy it, give it away
or re-use it under the terms of the Project Gutenberg License
included with this ebook or online at www.gutenberg.org. If you
are not located in the United States, you will have to check the
laws of the country where you are located before using this
eBook.
Language: English
Performed by Order of
BY
LEWIS DE BOUGAINVILLE,
LONDON,
M DCC LXXII.
TO
AND
1766-1769
A
VOYAGE
ROUND THE
WORLD.
PART the FIRST.