100% found this document useful (1 vote)
23 views

Extending Macromedia Flash MX 2004 Complete Guide and Reference to JavaScript Flash 1st Edition Keith Peters All Chapters Instant Download

Complete

Uploaded by

bilhaplenc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
23 views

Extending Macromedia Flash MX 2004 Complete Guide and Reference to JavaScript Flash 1st Edition Keith Peters All Chapters Instant Download

Complete

Uploaded by

bilhaplenc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 51

Download Full ebookname - Read Now at ebookname.

com

Extending Macromedia Flash MX 2004 Complete Guide


and Reference to JavaScript Flash 1st Edition
Keith Peters

https://ebookname.com/product/extending-macromedia-flash-
mx-2004-complete-guide-and-reference-to-javascript-
flash-1st-edition-keith-peters/

OR CLICK BUTTON

DOWLOAD EBOOK

Discover More Ebook - Explore Now at ebookname.com


Instant digital products (PDF, ePub, MOBI) available
Download now and explore formats that suit you...

Complete Flash Remoting MX 1st Edition Joey Lott

https://ebookname.com/product/complete-flash-remoting-mx-1st-edition-
joey-lott/

ebookname.com

Flash After Effects Second Edition Add Broadcast Features


to Your Flash Designs Chris Jackson

https://ebookname.com/product/flash-after-effects-second-edition-add-
broadcast-features-to-your-flash-designs-chris-jackson/

ebookname.com

Macromedia Dreamweaver MX Fast Easy Web Development 1st


Edition Aneesha Bakharia

https://ebookname.com/product/macromedia-dreamweaver-mx-fast-easy-web-
development-1st-edition-aneesha-bakharia/

ebookname.com

The Official Patient s Sourcebook On Gastrointestinal


Carcinoid Tumors Directory For The Internet Age Icon
Health Publications
https://ebookname.com/product/the-official-patient-s-sourcebook-on-
gastrointestinal-carcinoid-tumors-directory-for-the-internet-age-icon-
health-publications/
ebookname.com
Cities of the World Africa 6th Edition

https://ebookname.com/product/cities-of-the-world-africa-6th-edition/

ebookname.com

The End of Separation Gautam Sachdeva

https://ebookname.com/product/the-end-of-separation-gautam-sachdeva/

ebookname.com

Vaccines for Biodefense and Emerging and Neglected


Diseases 1st Edition Alan D.T. Barrett

https://ebookname.com/product/vaccines-for-biodefense-and-emerging-
and-neglected-diseases-1st-edition-alan-d-t-barrett/

ebookname.com

Tumor Diagnosis Practical approach and pattern analysis


2nd Edition Awatif Al-Nafussi

https://ebookname.com/product/tumor-diagnosis-practical-approach-and-
pattern-analysis-2nd-edition-awatif-al-nafussi/

ebookname.com

Introducing statistics 2nd ed Edition Upton

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

APress Media, LLC


Extending Macromedia Flash MX 2004:
Complete Guide and Reference
to JavaScript Flash
Copyright © 2004 by Keith Peters and Todd Yard
Originally published by Apress in 2004
All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or
mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior
written permission of the copyright owner and the publisher.
ISBN 978-1-59059-304-2 ISBN 978-1-4302-5472-0 (eBook)
DOI 10.1007/978-1-4302-5472-0
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every
occurrence of a trademarked name, logos, or image we use the names, logos, or images only in an editorial fashion
and to the benefit of the trademark owner, with no intention of infringement of the trademark.
The use in this publication of trade names, service marks, and similar terms, even if they are not identified as such, is
not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights.

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

About the Authors • • • • . . . . . • • • • • . . . . . . • • • • • xiii

About the Technical Reviewer. • • • . . . . . . • • • • • . . . . xiv

About the Cover Image . . . • • • • • . . . . . • • • • • . . . . . xv

Acknowledgments • . . . . . • • • • • . . . . . . • • • • • . . . xvii

Chapter 1: Introduction to Flash Extensibility . . . • • • • • . . . 1

Chapter 2: Custom Commands. . . . . . . . . . . . 19

Chapter 3: Custom Tools • . . . . . • • • • • . . . . . • • • • • • 65

Chapter 4: Timeline Effects . . . . • • • • • . . . . . • • • • • • 117

Chapter 5: XM L to UI . . . . • • • • • . . . . . . • • • • • 163

Chapter 6: Behaviors. . . . . . . . . . . 197

Chapter 7: WindowSWF and MMExecute •. • 239

Chapter 8: Flash from the Command Line . • 273

JSFL Reference • • • • • . . . . . • • • • • . . . . . . . . . . . . 293

Index . . . . .• . . . . . . . . . . 437

ii i
CONTENTS

Foreword . . . . . . . xi

About the Authors . . . . . . . xiii

About the Technical Reviewer. xiv

About the Cover Image. . xv

Acknowledgments . . . . . . . . . . . . . . . . xvii

Chapter 1: Introduction to Flash Extensibility . . . . . . . . . . . 1


What Is Flash Extensibility? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Timeline Effects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Behaviors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Advanced Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
What Extensibility Isn't . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
The Underlying Technologies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
JSFL-JavaScript Flash . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
The DOM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
XML to UI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Creating Your First Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
More Than Just a Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Tutorials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Sample Files and Supporting Website . . . . . . . . . . . . . . . . . . . . . . 15

v
CONTENTS

friends of ED Forums · . . . . . . . . . . . . . . . . 16
Styles Used in This Book . 16

Chapter 2: Custom Commands. . · .. . 19


The History Panel . . . . . . . . . . . . . . . . . . . . · ..... 20
Commands Through the History Panel . . . . . · ................ 23
Specifying Fill and Stroke Colors . . . . . . . · ................. 25
JSFL Commands . . . . . . . . . . . . . . . . . . . . . · ................. 26
Coding It By Hand . . . . . . . 30
Timelines, Layers, and Frames. 34
Accessing the Output Panel .. 36
Selections . . . . . . . . . . . . 39
User Input with XML to UI .. 42
Putting It All Together: Some Useful Commands ... · ................. 45
Selection to Grid .. 46
Text Effects . . . . . . . . . . . . . . . . . . . . · ................ 52
Adding ActionScript . . . . . . . . . . . . . . . · ................ 59
Summary . . . . . . . . . . . . . . . . . . . . . . . . . · ..... 63

Chapter 3: Custom Tools · .. . 65


Event-Based Code . . . . . . . . . . . . . . . . . . . . . . . . . . 67
Standard Tool Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
Setting Up a New Tool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Creating a Tool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Grid Tool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Adding Options . 80
Custom Cursors . . . . 83
Snap to Grid. . . . . . 84
Constraining a Shape. 86
Enter the Matrix. . . . 88
Arrow Tool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
The Path . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
Setting the Properties Panel . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
3D Cube Tool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
Packaging Extensions 112
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115

Chapter 4: Timeline Effects . . 117


Timeline Effects vs. Commands. 118
Blur Effect . . . . . . . . . . . . . . . . 119
Creating Timeline Effects . . . . . . . . 123
Slide Effect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
Removing an Effect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
Move in Circle Effect . . . . . . . 133
Easing the Pain of Development. 141
Checkerboard Transition Effect . 142

vi
CONTENTS

Custom Effect UI and Preview 149


Summary . . . . . . . . . 160

Chapter 5: XML to UI . 163


XML to UI in Action .. . · ........ 164
The Beauty of XML .. . · ........ 166
Elements . . . . 167
Attributes .. . 167
Character Data 167
Comments. 167
Root . . . . 168
Declaration 168
XML to UI tags . . . . . . . . . . . . . . . . . . . . . · . . . . . . . . . . . . . . . . . 168
Layout Tags . . . . . . . . . . . . . . . . . . . · . . . . . . . . . . . . . . . . 169
Control Tags . . . . . . . . . . . . . . . . . . . · . . . . . . . . . . . . . . . . 170
Creating a Dialog Box . . . . . . . . . . . . . . . . . · . . . . . . . . . . . . . . . . . 172
SWF in a Window . . . . . . . . . . . . . . . . · . . . . . . . . . . . . . . . . 173
Dialog Layout . . . . . . . . . . . . . . . . . . · . . . . . . . . . . . . . . . . 176
<dialog> 177
<hbox> .. 178
<vbox> .. 178
<separator> 179
<grid>, <columns>, <column>, <rows>, <row> 180
<spacer> . . . . . . . . . . . . . . . . . . . . 181
Dialog Controls . . . . . . . . . . . . . . . . . · . . . . . . . . . . . . . . . . 182
<button> . . . . . . . . 182
<checkbox> 183
<radiogroup>, <radio> 184
<label>, <textbox> .. 184
<colorchip>, <popupslider> 186
<menulist>, <menupop>, <menuitem>, <listbox>, <listitem> 188
<targetiist> . . . . . . 189
<flash>, <property> . 191
Dialog Designer 193
Summary . . . . . . . . . 195

Chapter 6: Behaviors . 197


Exploring Behaviors . . . ..... . · ........ 198
Behind the Scenes . . . . . . . . . . . . . . . · ................ 201
Snippet Behaviors . . . . . . . . . . . . . . . . . . . · ................. 203
Root Preloader . . . . . . . . . . . . . . . . . · ................ 204
Button Action Behaviors . . . . . . . . . . . . . . . · ................. 207
Drag and Throw Physics in Flash . . . . . . . · ................ 207
Designing the Drag Dialog Box . . . . . . . 212
Throwing Behaviors Around . . . . . . . . . · . . . . . . . . . . . . . . . . . 216
Keeping Things in Check . . . . . . . . . . . · . . . . . . . . . . . . . . . . . 220
Dynamic Properties with SWF Dialog Boxes . · . . . . . . . . . . . . . . . . 222

vii
CONTENTS

A Flash Component Interface 222


Custom Right-Click Menu .. . 226
Behavior Clips . . . . . . . . . . . . . 230
Following the Leader . . . . . . . . . . . . . . · . . . . . . . . . . . . . . . . 231
Summary . . . . . . . . . . . . . . . . . . . . . . . . . ........ 237

Chapter 7: WindowSWF and MMExecute · 239


What's New with WindowSWF? . 241
MMExecute . . . . . . . . . . . . . . . . . . . . . . . · . 242
Case Study 1: Message Window . . . . . . . . . . . · . 243
Creating the Interface 244
Interface Code . . . . . . . . . . . . . . . . . · . . . . . . . . . . . . . . . . 245
Custom Functions . . . . . . . . . . . . . . . . · . . . . . . . . . . . . . . . . 247
Case Study 2: Search and Replace . . . . . . . . . . · . . . . . . . . . . . . . . . . . 250
User Interface . . . . . 251
Finding a Phrase . . . . 252
Continuing the Search 260
Replacing Phrases . . . 265
Recursion, Recursion, Recursion! 268
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270

Chapter 8: Flash from the Command line . · 273


Why the Command Line? . . . . . . . . . . . . . . . . ........ 274
How to Execute a JSFL File . . . . . . . . . . . . . . . . . . . . . . . 275
Calling Flash from the Command Line 275
Calling the JSFL File Directly . . . . . . . . . . . . . . . . . . . . . . . . . . . 278
Executing a File from Its Icon . . . . . . . . . . . . . . . . . . . . . . . . . . 278
Adding Content via the Command Line . . . . . . . . . . . . . . . . . . . . . . . . . 278
Saving and Publishing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280
Closing Flash . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280
Processing Existing Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282
Handling External Files from JSFL . . . . . . . . . . . . . . . . . . . . . . . . 283
Abstracting It Even Further with Batch Files . . . . . . . . . . . . . . . . . . 285
Echoing Data. . . . 285
Getting Arguments . . . . . . . . 286
Creating a JSFL File . . . . . . . . 286
Executing Files from a Batch File. 288
Handling Multiple Arguments 288
Summary . . . . 290

JSFL Reference · 293


Bitmaplnstance . 296
Bitmapltem . . . 297
CompiledCliplnstance 298
Componentlnstance 300
Components Panel 300
Contour . . . . . . . 300

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.

I applaud the authors-both experienced developers-who have managed to cover such


an immense subject very accurately and concisely, creating the only book you will ever
need at your desk when creating Flash extensions. I for one am very excited at the thought
of all the crazy new features that Flash users will be distributing throughout the Flash com-
munity in the not-so-distant future, after reading this book.

I wish you luck and happy reading!

Guy Watson, a.k.a. FlashGuru

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.

Todd Yard studied acting at London's Mountview Theatre School


and performed in New York, Los Angeles, and on tour nationally
before settling in New York to pursue graphic design and web
application programming full time. Since 1999, Todd has taught
classes in Photoshop, Illustrator, and Flash, contributed as an author
to eight friends of ED Flash books including Macromedia Flash MX
Studio and Flash MX Application and Interface Design, served as
technical editor for Flash MX 2004 Games Most Wanted, and has
written more than a few Flash, Photoshop, and Illustrator tutorials
for computer magazines in the UK. His personal web site,
www.27Bobs.com. has been featured in a number of articles and international festivals,
including the Flashforward Film Festival in Amsterdam and the Electronic Language
International Festival in Brazil. Todd now works as lead Flash programmer at Ego? in
New York City, in addition to his freelance writing, coding, and animation projects.

xiii
ABOUT THE TECHNICAL REVIEWER

Peter Elst is a freelance multimedia application developer and runs


a small business called MindStudio, which specializes in Flash devel-
opment and content management tools. As a Team Macromedia
volunteer, contributor to various community resources, and
speaker at several international venues, he happily spends any
spare time he has on replying to e-mailed questions and posting on
his personal weblog (www.peterelst.com).

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.

What Is Flash Extensibility?


Let's take a look at the five main areas that fall under the heading of extensibility in Flash:

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

Run Commond ...

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_

Figure 1-3. User interface for the Blur Timeline Effect

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.

MMExecute is actually a new ActionScript built-in function. It takes a single argument,


which is a string. The string itself is actually a program in the same language as the com-
mands, tools, and Timeline Effects are written in, jSFL. For example, the following is a very
simple program written in jSFL that simply adds a circle to the current document:

var the_doc = fl.getDocumentDOM();


the_doc.addNewOval({top:l00, bottom:l00, left:2oo, right:200});

You can encode that into a string and store it in a variable like so:

thejSFL = "var the_doc =


-.fl.getDocumentDOM();the_doc.addNewOval({top:l00, bottom:l0o,
-.left:2oo, right:200});"

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.

What Extensibility Isn't


As touched upon previously, the extensibility tools only have power within the Flash
authoring environment itself. The final SWF movie that you publish and put on a website
or CD or whatever isn't going to be able to do anything that it couldn't do before you
extended Flash. These tools are all strictly for you, the Flash author, to make your job
easier or to add more power to your creative abilities.

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.

To reiterate, the new extensibility features are enhancements to the authoring


environment of the Flash IDE. They are there to speed up the workflow for you,
the Flash designer or developer, or to make it possible to simply do things you
just couldn't do before. Once your movie is exported to a SWF or published on a
web page, the end audience isn't going to have access to any of these features.
The main benefit that they will see is higher quality work and more of it, pro-
duced faster by you and your design team!

The Underlying Technologies


In addition to extensibility architecture, you might have heard the terms JavaScript API
and JSFl. This has caused confusion among some, giving the impression that this somehow
enables some communication between a Flash movie and javaScript within a browser.
Remember, extensibility has nothing to do with the final SWF in the browser. We even had
one person tell us that Macromedia has done away with ActionScript and replaced it with
javaScript! So, let's look over the technologies that we'll be using throughout the book,
and how javaScript relates to it all.

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:
But Junior shook his head. "I'm very sorry," he said, "but I can't do it."
And though the crab kept on coaxing and coaxing, he wouldn't give
in.
"Now look here," said Mrs. Sand Witch, "if we keep this up the dinner
will be cold. So run along, Bertha, and maybe after Junior has had a
good dinner he will change his mind."
"No, I won't," said Junior. "And what is more I want to go back to the
beach right off. I told you I was going sailing with my father in a half
hour."
"But," replied Mrs. Sand Witch, as she smacked her lips over the last
of her sandpaper, "that was before you were engaged to be
married."
"I'm not engaged to be married," stormed the boy; "and if I had
known you were this kind of a person I'd never have come down
here."
"Now, now," said Mrs. Sand Witch, "I'm every bit as old as your
mother, and I know what is best for you. You wouldn't like me to
spank you, would you?"
And when she said that, Junior decided he might as well give himself
up for lost. Soon as a person began to say she knew what was best
for you, you might as well make up your mind, you are done for.
"Good gracious!" he said to himself, "whatever shall I do?"
And when dinner was over, and he went into the park again with the
little Sand Witches, he was so depressed he wouldn't play or do
anything; and finally, Ham Sand Witch got tired trying to cheer him
up and went off to play with some other sand witches, leaving Junior
and Lettuce Sand Witch sitting on a bench side by side.
Lettuce Sand Witch, swinging her legs violently, was looking at him.
Then she slid along the bench and snuggled up close. "I'm awfully
sorry," she said. "And I think it's dreadfully mean to make you marry
Bertha. She's not pretty like I am, is she? Wouldn't you rather marry
me?"
And the minute she said that, Junior had a bright idea. He didn't
want to marry Lettuce Sand Witch any more than he wanted to marry
the grateful Bertha, one was as ugly as the other; but maybe if he let
on he wanted to, she might tell him how to get back to the beach. So
he snuggled up to her when she snuggled up to him.
"Maybe I would," he said, smiling at her. "But I couldn't possibly do it
until I asked my mother. You tell me how to get back to the beach,
and if my mother says I can marry you, I'll come right back and do it."
"Oh, will you, really?" cried Lettuce Sand Witch, springing to her feet
and clapping her hands. "Then I'll tell you how to get to the beach, or
at least the way my mother gets there. She stands up straight like
this; holds her nose with her left hand and puts her right hand above
her head; then she blows out her breath instead of drawing it in; and
up she goes. And now, you won't forget to come back?"
"No, indeed," said Junior, "I'll do just as I promised. If my mother tells
me to come back and marry you, I'll do it. And now, good-by, and
thank you very, very much."
The next instant he stood up as straight as he could, grasped his
nose with his left hand, put his right hand above his head, blew out
his breath, and bing—he shot up through the sand, and found
himself right alongside of his bucket and shovel.
He looked about. Everything was just the same. The sun was
shining, people were still in bathing, but nowhere among them could
he see his father, or mother, or sister. And then, presently they came
tearing over the sand toward him.
"You bad boy!" scolded Mrs. Jenks. "Where have you been? We've
been terribly worried! How dare you go off by yourself? Where were
you, I say?"
"Why—why—" began Junior.
Then he stopped. What was the use? He knew they wouldn't believe
him. And if he asked his mother if he could go back and marry
Lettuce Sand Witch as he promised he would ask her, she would say
he was sick or something, and make him go to bed. So he just dug
his toes into the sand and said nothing.
And that is why poor little Lettuce Sand Witch is still waiting
underneath the sand for Junior Jenks to come marry her. And that is
why Junior Jenks keeps looking about so queerly when he plays on
the beach by himself. He is taking no chances of another sociable
sand witch popping up in his neighborhood.
THE FOUNTAIN OF RICHES
No matter what other mistakes you may make in your lifetime, never
make the mistake of renting a cottage from an ogre. If you do, the
chances are you will bitterly regret it, as did Hak, the aged
woodcutter.
Hak, was an old, old man who lived in a forest with his little
grandson, Omo, whose father and mother were dead; and who
earned his living by cutting down trees and chopping them into
firewood. The cottage that Hak and his grandson lived in belonged to
an ogre, and the rent the old man paid for it was not very much; and
as long as he kept his health and strength, he got along very nicely.
But one day, while cutting down a tree he tripped and fell, and before
he could get out of the way the falling tree struck him and broke his
leg. And after Omo had dragged him back into the cottage all he
could do was to lie on his bed and groan, and wait for the leg to get
well.
"Goodness gracious!" he said to the boy, "What shall we do? I won't
be able to work for days and days, and there will be the rent to pay,
to say nothing of the doctor's bill."
"Well," said Omo, "the rent and the doctor's bill will have to wait. So
don't worry."
"I have to worry," replied the old man. "The doctor may wait for his
bill, but the person who owns this cottage will not wait for his rent; no
sir-ee."
Then he told Omo that the cottage belonged to an ogre. "He let me
have it very cheap, but only for a certain reason. What do you think
that reason was?"
"I don't know," replied Omo. "What was it?"
"That he should be allowed to make you into a dumpling for dessert
if I did not pay the rent every month without fail."
"Oh," said Omo, his eyes very big. "I don't wonder you are worried. It
—it makes me feel worried, too! Why did you ever make such a
bargain?"
"Well," said his grandfather, groaning worse than ever, "I never
thought for a minute that I would ever have my leg broken, and I was
so very, very poor I simply had to have a cottage cheap. But now, I'll
not only lose the cottage, but you also. I guess I might as well die."
"Don't you do it!" responded Omo. "I haven't been made into a
dumpling yet, and I'm not going to be, if I can help it. I'll go into the
city and get the doctor, and while I'm there I'll try to earn enough
money to pay the rent."
But Omo's grandfather only shook his head. "You're a plucky boy,
Omo," he said, "but you'll never be able to do it. How can a boy of
seven earn anything?"
"Well, I can try, can't I?" said Omo. "You can't do anything if you don't
try."
So pulling his cap down over his curls, and tucking some bread and
cheese into his pocket, he set off for town. But when he arrived at
the doctor's office he found that the waiting room was crowded with
people, and that he would have to wait his turn.
"Oh, dear," he sighed, as he sat down next to a little old lady with a
frilled bonnet on her head, "this is most unfortunate. My grandfather
ought to be attended to right away."
"Well, he won't get attended to right away," said the old lady, "I can
tell you that! This doctor charges by the length of time you wait in his
office, so he never hurries. I've been here three months."
"Three months!" cried the boy. "Oh, I couldn't possibly wait three
months, or even three days. I'm in a hurry! I've got to earn enough
money to pay the rent of our cottage, or the ogre who owns it will
turn me into a dumpling and eat me."
And when he said that everybody in the waiting room twisted about
and looked at him. "He seems to have a fever," they said.
"See here," said the old lady, "are you sure you're not sick instead of
your grandfather?"
"I'm perfectly well!" exclaimed Omo, indignantly.
"Then you must be joking," responded the other.
"No, I'm not," said Omo. "I mean every word I said. I'm in great
trouble."
"H'm," said the old lady. She got to her feet. "Come on, let's go
outside! We'll save money by it anyway!"
Then as they walked along the street Omo told her all about his
grandfather's accident, and how important it was that the rent should
be paid.
"Ha!" exclaimed the old lady. "I know that ogre! His name is Gub and
he lives on the hill on the other side of the city. I often used to help
people out of his clutches. I'm a retired fairy godmother—haven't
been in business for years and years—but your story interests me.
I've a good mind to help you!"
"Oh, if you only would!" said Omo, "I'd be awfully obliged. You see,
it's not very pleasant to be made into a dumpling, and have my
grandfather put out of his cottage when he has a broken leg. Please,
please, help me!"
"Well," said the old lady, as she led the way into a little house with a
peaked roof, "I only help people who help themselves. Can you help
yourself?"
"Certainly!" said Omo. "Just offer me something and watch me help
myself."
"Very well then, I will," responded the fairy godmother. Going to a
golden desk in a corner she took from it a silver key. "This is the key
that turns on the Fountain of Riches in the City of Ootch. All you
have to do is to put the key in the keyhole at the base of the fountain,
give three turns to the right, three turns to the left, and one turn in the
middle, and instantly the fountain will commence to spout gold
pieces enough to bury you. But you must promise me this, be sure
and turn the fountain off as soon as you get enough gold pieces to fill
your cap; and be sure and bring the key back to me, for I wouldn't
want that key to be left in Ootch, or that fountain to be left spouting,
for anything."
"Why not?" asked Omo. "What's the use of a fountain if it doesn't
spout?"
"Well, you see I presented that fountain to the city of Ootch because
they named the city after my great aunt's trained cockatoo, but after
the fountain started spouting gold pieces everybody had so much
money they all stopped working, and it almost ruined them. The
butcher stopped selling meat, and the baker stopped baking bread,
and the tailor stopped making clothes. Everybody stopped doing
everything, and pretty soon, although everybody had plenty of
money, you couldn't buy anything because nobody would take the
trouble to keep store when they could get money from the fountain.
So I locked the fountain up and took the key with me. And after the
people of Ootch had spent some of the money they had, and lost the
rest, and could not get any more without working for it, everything
got all right again. And that's the reason I don't want the fountain to
keep on spouting again, or want you to leave the key behind you."
"I should think not," said Omo. "It seems as bad to be too rich as it is
to be too poor. I'll be very careful about shutting the fountain off, and
I won't forget to bring back the key. And now how do I get to the city
of Ootch?"
"Just open my back door," said the fairy godmother, handing him the
key, "step out on the step, and then step off. And I do hope you won't
find it raining, for when it rains in Ootch, it rains cats and dogs."
So Omo opened the fairy godmother's back door and stepped out on
the step, and as he stood there all he saw before him was a pretty
little garden. Then, he stepped off the step, and bing—he was in a
queer looking city, and the garden and the back step, and the
cottage, and the fairy godmother, had all disappeared. And in
addition it was raining cats and dogs; regular, real cats and dogs.
"Ouch!" cried Omo, as a fat maltese fell ker-plunk on his head,
yowling like anything. "Whee!" he yelled, as a fox terrier dropped
with a thud on his shoulder and barked in his ear. And then, as black,
white, brown, yellow cats of every color, and dogs, big, little and
medium, began pouring on him and around him, all howling, and
barking, and spitting at the same time, he made a rush for a small
building, open at the sides but with a dome like roof of metal, where
a man was standing.
"Quite a shower, isn't it?" said the man, as Omo reached the shelter.
"A shower," gasped Omo, "why—why, I think it's much more than a
shower. And—and look what's coming down—cats and dogs!"
It was raining cats and dogs

"Well," said the other, "why not? That's what always comes down,
isn't it? That is why we build these cat and dog proof pavilions for
use on rainy days. Now if it rained elephants, that would be an
inconvenience."
"I should say so," replied the boy. "But does it always rain like this?"
"Oh, sometimes it's a great deal worse. I remember about two years
ago I was caught in a storm and eight cats, all in one lump, and
fighting as hard as they could, fell right on top of me as I crossed the
street, and I assure you, sir, I almost lost my temper."
"Well," said Omo, "it's lucky they melt as soon as they reach the
ground or you'd have more cats and dogs than you knew what to do
with."
"Quite true," responded the stranger, "and even as it is, it is quite a
nuisance when a storm comes up."
He was an odd looking fellow with a curly beard, a scimitar in his
sash, and a spotted turban on his head. As he finished speaking he
began twisting at his ear with his finger as though he were winding a
clock.
"What's the matter," asked Omo, "is your ear sore?"
"Certainly not! You know as well as I do I'm only winding myself up
so I can start home as soon as the storm passes."
"Oh," cried Omo, "is that it? Well, I don't have to wind myself up
when I want to go anywhere. I'm always wound up."
"You are!" exclaimed the stranger. "Why, I can hardly believe it! I
never heard of anyone being that way! You can't have lived here
very long."
"Oh, no," said the boy, "I haven't lived here a half hour. I only just
came."
Then he asked his companion if this was the city of Ootch, where the
famous Fountain of Riches was located.
"Oh, yes," said the stranger, "this is the city of Ootch all right. And
the Fountain of Riches is here, too, but it's turned off; been turned off
for years. Gee whiz, don't I remember the good old days when it was
turned on. Everybody got so rich we nearly starved to death because
nobody would work to provide things for us to live on. And then all of
a sudden the fountain stopped, and I had to go to work again. I'm a
night watchman. Not that there is much use of watching the night,
because no one ever tries to steal it, but that's the trade my father
taught me, so I'm it. And now, maybe you'll tell me why you ask
about the Fountain of Riches?"
"Well," said Omo, cautiously, "I've heard so much about it I just
thought I'd like to see it while I was here." He didn't think it wise to
tell anything about the fairy godmother giving him the key to the
fountain for fear some one might try to take the key from him.
"Quite so," said the other, "then you'd better come with me. The
shower is over now, and if you want to see the fountain you've got to
get a permit from the Doodab."
"The Doodab! What's a Doodab?" asked Omo.
"A Doodab," exclaimed the Night Watchman, "is the next swellest
person to a Gumshu. Ootch isn't important enough to be governed
by a Gumshu so they put a Doodab over us, and he's a right decent
chap, and very fond of music. Why I've seen him sit by the hour and
push a slate pencil across a slate and go into ecstasies because it
made his blood run cold. You'll probably like him if you don't hate
him. So come along and see for yourself."
Now the Doodab of Ootch was a very, very fat, and a very, very lazy
gentleman. He hated to be bothered about anything at any time. He
wore rings on his fingers and bells on his toes, and he had a big
hoop of pearls through the end of his nose. And he especially hated
to be bothered when he was singing, which is what he was doing as
Omo and the Night Watchman entered his apartment. And this is
what he was singing in a very quivery voice as he accompanied
himself on a slate with an awfully squeaky slate pencil:

The currant cakes were thick upon the bushes;


The pie plants they were swaying in the breeze,
And the river it was made of delicious lemonade.
While the doughnuts all were ripe upon the trees.
We wandered hand in hand about the garden
Where the lollipops were strolling to and fro;
And I always will recall that exciting day in Fall
When we stood and watched the pickled onions grow.

"Well," exclaimed the Doodab, fretfully, "what do you want? It seems


strange I can't embark on a sea of melody without being dragged
ashore like this. What do you want?"
"This boy wants to get a permit to look at the Fountain of Riches,"
said the Night Watchman.
"He wants—What does he want that for?"
"Oh, I just want to see what it looks like," said Omo. "I never saw a
Fountain of Riches before."
"Hum!" said the Doodab of Ootch. "That remark has a very jarring
note in it. And what are you going to do after you've seen the
Fountain of Riches?"
"Why," said Omo, "just—just look at it, of—of course."
"And what are you going to do after that?"
"Why—why, just—just keep on looking at it, I guess," responded the
boy, hardly knowing what to say.
"Nonsense!" said the Doodab, "it won't do any good to keep on
looking at it forever. And besides if you look at it too long the permit
will run out. It only lasts three minutes."
"Three minutes!" exclaimed Omo. "Oh, I couldn't turn the fountain on
and off, and gather up the gold pieces in three minutes." And then he
clapped his hand to his mouth in dismay when he realized what he
had said.
"Ah, ha!" said the Doodab of Ootch, rattling the bells on his toes. "So
you're going to turn it on, eh?"
"Oh, ho!" said the Night Watchman. "And how in the world did you
find out how to turn it on?"
"Oh, I found out!" replied the boy.
"Well," said the Doodab, "I'm mighty glad to hear it, for I'm dreadfully
hard up. My purse is just about empty."
Then he clapped his hands and when his servants entered the room,
he told them to get several large sacks and some shovels, and follow
him. Then having twisted his ear and wound himself up, while the
Night Watchman did the same, he took Omo by one hand and the
Night Watchman by the other, and led the way to the Fountain of
Riches.
"See here," said Omo, as they hurried through the streets, "you two
needn't think you're going to have piles of gold pieces again, for
you're not. I'm only going to turn that fountain on long enough to get
my hat full; and then I'm going to turn it off."
"What!" shrieked the Doodab of Ootch, "you're going to turn it off
before I get my sacks full?"
"Can I believe my ears?" said the Night Watchman. "You can't mean
to turn it off before I get my pockets full? Why—why if it hadn't been
for me you never would have seen the Doodab, or found out where
the fountain was. You must be spoofing!"
"No, I'm not," said Omo. "I'm very sorry, but I promised to turn the
fountain off the minute I got my hat full."
"The minute you get your hat full, eh?" said the Doodab, looking at
Omo slyly. Then he whispered in the Night Watchman's ear, after
which they both laughed merrily.
"What are you laughing at?" asked Omo.
"We're laughing," said the Night Watchman, "to think how you're
going to turn the fountain off after you get your hat full."
By this time they had reached the Fountain of Riches which was in
the center of the public square of the city.
"Are you still determined to turn it off as soon as you get your hat
full?" asked the Night Watchman.
"I have to," said Omo. "I promised."
"Well," said the Doodab, snappishly, "if you want to shut it off you've
got to turn it on first, haven't you? So go ahead!"
So Omo took out the silver key, fitted it into the keyhole at the base
of the fountain, and turned three times to the right, then three times
to the left, and then three times in the middle, and bing—with a clink
and a chink, and a tinkle, the fountain of riches began to spout. And
the minute it did that, the Night Watchman grabbed Omo's cap from
his head, and the Doodab snatched the key from his hand.
"There," said the Doodab of Ootch, hurling the key as far as he
could, "I guess you won't turn off the fountain until you find that key."
"Yes," said the Night Watchman, hurling Omo's cap as far as he
could, "and I guess you won't fill your cap until you find your cap
either. And by the time you do I'll have my pockets full of gold
pieces."
"And," put in the Doodab, "I'll have my sacks full also."
Well, you may be sure Omo was very angry at the trick played on
him, and started after the cap and key as quickly as he could. It did
not take him long to find his cap, but he simply could not find the key.
"See here," he cried, running back to where the Doodab was tying
up the necks of his sacks, which were now filled to bursting, "you've
got to help me find that key. I promised to turn this fountain off and
I'm going to do it."
"All right," said the Doodab, "I'll help you. I've got gold enough here
to last me the rest of my life so I don't care how soon you turn it off."
"Nor I," said the Night Watchman. "I've got all my pockets full, and
my stockings full besides, so stop the old thing whenever you want."
But Omo, and the Doodab, and the Night Watchman, although they
searched and searched, could not find the key anywhere, and all the
while the fountain was spouting gold pieces in a stream a hundred
feet high, and so thick it looked like smoke.
"My sakes!" said the Doodab of Ootch, "I don't know how you'll ever
stop it! I'm sorry I threw the key away now! But, anyhow, the worst
that can happen if the fountain keeps on spouting, is to give the town
a spell of nervous prosperity."
But alas, the Doodab of Ootch did not know what he was talking
about, for the fountain kept on spouting and spouting, faster and
faster; and presently the streets were knee deep in gold pieces. It
was awful.
"Say," said the Night Watchman to Omo, "are you sure you turned
the fountain on all right? It never spouted like this before. We've
always been able to pick up the gold pieces as fast as they came
out."
"Of course I turned it on right," said the boy. "I turned the key three
times to the right and three times to the left, and then once in the
middle."
"No such thing!" shrieked the Doodab. "No such thing! You turned it
three times in the middle! I watched you!"
"Oh," cried Omo, in a horrified tone, "did I? Then—then that's why
the gold is coming out so fast. And it's getting deeper all the time."
"It'll soon be up to our necks!" cried the Night Watchman.
"We are lost!" roared the Doodab. He glared at Omo angrily. "How
dared you turn it on wrong?"
"Well, what did you throw the key away for?" retorted the boy. "If you
hadn't done that, I could turn it off."
And there they stood quarreling, and all the time the gold was getting
deeper and deeper about them. And when at last they decided they
had better go back to the Doodab's palace before they were buried
alive, they found it was too late. The gold pieces were so deep they
could not walk.
"Mercy me!" groaned Omo. "I'll never get back to my grandfather
now. I wish I had never come here!"
"So do I!" snapped the Doodab of Ootch. "Until you came I was
perfectly poor and happy, and now I'm horribly rich and wretched.
Oh, what shall we do?"
And then all of a sudden Omo remembered a whistle the fairy
godmother had given him when she gave him the key. "If you really
need me for anything," she had said, "just blow this whistle; but not
unless you really need me." So Omo put the whistle to his lips and
blew as hard as he could, for he thought if he ever really needed a
fairy godmother he needed one now.
And the minute he blew the whistle there was a flutter and a whirr,
and the fairy godmother, frilled bonnet and all, stood before them.
"Well," she said, "you are in a nice mess, aren't you?"
"It isn't my fault," said the boy. And then he told her how he had tried
to obey her instructions, but could not because the Doodab of Ootch
had thrown the key away. "I did make a mistake turning the fountain
on," he said, "but I could have turned it off all right if the key had not
been taken from me."
"I see!" said the fairy godmother.
Then she told Omo to fill his cap as well as his pockets with gold
pieces. And after he had done it, she gave three clucks like a
chicken does, snapped her finger twice; and bing—all the gold
pieces in the streets of Ootch, all the gold in the Doodab's money
bags, all the gold in the pockets and stockings of the Night
Watchman; all the gold everywhere except that which Omo had,
disappeared, and the Fountain of Riches also.
"There," she said, "that's the best way to settle the matter. And now,
come on, Omo, and get the doctor for your grandfather and pay the
ogre his rent."
"But," howled the Doodab of Ootch and the Night Watchman, "what
do we do? We haven't a cent!"
"You don't deserve any," replied the fairy godmother, sternly. "And as
long as you're howling so about it, I'll just make you and the whole
city disappear as well."
And she did, with three clucks and a snap of her fingers; and the
next moment Omo found himself in the fairy godmother's cottage.
Well, you can easily guess how after thanking his benefactress for
what she had done, he hurried off to the doctor's office. And when
the doctor saw Omo's cap and pockets full of gold, he went with him
at once; and became so interested in Omo's grandfather's case he
took ten years to cure him.
But neither Omo nor his grandfather cared if he did, for they had
plenty of money. And when the ogre came stamping in to collect his
rent, thinking he would not get it and would then make Omo into a
dumpling, Omo just laughed and bought the place from him. And not
only that, but he added another wing to the cottage and laid out a
pretty garden as well, as much like the fairy godmother's as he could
make it. And when he did that the fairy godmother was so pleased
she came and kept house for them.
And now if you want to see a really happy family, just stop and make
a visit at Omo's place in the middle of the forest where his
grandfather used to cut down the trees to make a living, but which he
does not have to do any more, thanks to the Fountain of Riches.
OBSTINATE TOWN
Of course you know what a postage stamp is: a little, square,
gummed stamp with a picture of George Washington on it. But a
magic postage stamp is a very different stamp indeed. The George
Washington kind you can buy in the drug stores, but the other sort
you cannot buy. They are given to you free of charge, if you don't
look out.
In the autumn, when the leaves are falling, the Poppykoks come to
town. There may be a hundred leaves falling and not one leaf have a
Poppykok on it, and then all of a sudden, another leaf falls on your
shoulder and a Poppykok is sitting on it, and then—bing—the
moment he lands on your shoulder he jumps off the leaf and pastes
a magic postage stamp on your cheek, and then—off you start for
Obstinate Town by special delivery, that is, you do if you happen to
be a boy that always wants his own way. But if you are not that kind
of a boy, you need not worry.
However, the boy this story is about was one of the kind who wanted
his own way. No matter what he was told to do he wanted to do
something else. Otherwise, he was a very nice little chap, and his
name was Prince Zep, the only son of a wealthy and powerful king.
Of course being a prince he was allowed to have his own way much
more than was good for him, and was so used to it, he never thought
anything about how unpleasant it might make things for other
people.
And so, it is not surprising that one afternoon late in the Fall he was
caught, and sent off to Obstinate Town by special delivery.
Now Zep never guessed, any more than you have, that there was
such a place as Obstinate Town, or such things as Poppykoks or
magic postage stamps. And so, as he strolled through the Royal
Park that afternoon scudding his feet through the dried leaves that
covered the way, he had not the slightest idea that anything was
going to happen to him, until quite unexpectedly, a big, red maple
leaf fell on his shoulder, and from it stepped a Poppykok in his bright
scarlet coat and breeches, and with his magic postage stamp neatly
curled up in a roll in his hand. And before Zep could even gasp, the
Poppykok had pasted the stamp on his cheek, leaped from his
shoulder to the ground, and stood before him, smiling cheerfully.

The Poppykok pasted a magic postage stamp on his cheek


"There you are," said the Poppykok, "a good job, well done. Bon
voyage!"
"Bon what?" began Zep, "I—I—"
"That's all right," responded the Poppykok, "you don't know where
you're going, but you're going. Good-by! I'll see you later!"
And then Zep felt himself leap into the air and start off with a whiz.
And the more he whizzed, the more he whizzed, until it seemed as
though he would never stop whizzing.
"My gracious," he thought, as well as he could as he hurried along,
"what on earth has happened to me, and where, oh where, am I
going? This is really dreadful!"
And indeed it was for a little while. But presently he began to get
used to the whizzing, and finally found himself descending in a
graceful curve before a large and ornate building that looked very
much like a palace. And sure enough that is exactly what it was, and
sitting on the steps of the palace waiting for him was the very same
Poppykok that had started him off on his journey.
"Welcome!" said the Poppykok, rising and coming forward as the
Prince reached the ground with a bump, "you're right on time. I hope
you had a pleasant trip?"
"No," said Zep, crossly, "I certainly did not. I had a horrid trip. How
dare you treat me this way?"
"Pooh! Pooh!" responded the other, snapping his fingers, "everybody
says that when they first arrive. You'll be crazy about the place in a
little while. And now let's go inside and report to the Emperor."
Pushing open the front door of the palace the Poppykok led the way
into the grand entrance hall, and as he did so a short, fat man with a
crown on his bald head, and bristling whiskers all about his face,
came tumbling down the stairway head over heels, and landed in a
heap at their feet.
"Ouch!" he exclaimed, sitting up and rubbing his nose. After which
he rubbed his shins and said "ouch" once more; and "oh my" and
"good gracious." And after that he bawled up the stairs as loud as he
could: "Don't try to tell me to be careful and not fall downstairs, for I'll
do as I want."
Then he swung himself about. "The idea," he said, glaring at the
Prince and the Poppykok, "of any one trying to keep me from falling
downstairs. Huh! Can't I fall down my own stairs? Can't I? Tell me!"
"Certainly you can, your majesty," responded the Poppykok. "You
can fall up 'em, too, if you want."
"I should think so," retorted the Emperor, "and yet the Queen tells me
to look out and not fall down 'em, because it worries her. Well, let her
worry. I want her to worry."
But if the Queen was worried she did not act that way, for as she
came tripping down she was laughing so heartily that she nearly fell
herself, and finally had to sit on the bottom step to get her breath.
"What—what—" spluttered the Emperor, "what do you mean by not
worrying? You ought to be ashamed of yourself. Look at my nose, to
say nothing of the bump on my shins. My, oh, my, isn't anybody
worried about me?"
"I am, your majesty," put in Zep, "and I think the Queen ought to be,
too."
"She ought not," snapped the monarch, scrambling to his feet. "If I
wanted her to be glad she would be worried, but as I want her to be
worried, she is not. You must be a stranger here."
"He is," said the Poppykok. "He just arrived. I only caught him a little
while ago."
Then he told the Emperor who Zep was. "This boy," he said, "is a
Prince, and has his own way more than anybody else in his father's
kingdom. In fact, he is one of the most delightfully stubborn young
persons I have ever met, and never will do what any one wants him
to if he can possibly help it."
"My," said the Emperor, grasping Zep's hand and shaking it warmly,
"if that isn't the finest record I ever heard of. I couldn't be more pig-
headed myself. How did you get so? Did you learn it at school or just
teach yourself?"
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookname.com

You might also like