1. Programming Flex 2 Chafic Kazoun Joey Lott
download
https://ebookbell.com/product/programming-flex-2-chafic-kazoun-
joey-lott-4106486
Explore and download more ebooks at ebookbell.com
2. Here are some recommended products that we believe you will be
interested in. You can click the link to download.
Programming Flex 2 Chafic Kazoun Joey Lott
https://ebookbell.com/product/programming-flex-2-chafic-kazoun-joey-
lott-36656048
Programming Flex 3 The Comprehensive Guide To Creating Rich Internet
Applications With Adobe Flex Chafic Kazoun
https://ebookbell.com/product/programming-flex-3-the-comprehensive-
guide-to-creating-rich-internet-applications-with-adobe-flex-chafic-
kazoun-46370970
Programming Languages And Systems 31st European Symposium On
Programming Esop 2022 Held As Part Of The European Joint Conferences
On Theory And Practice Of Software Etaps 2022 Munich Germany April 27
2022 Proceedings Ilya Sergey
https://ebookbell.com/product/programming-languages-and-systems-31st-
european-symposium-on-programming-esop-2022-held-as-part-of-the-
european-joint-conferences-on-theory-and-practice-of-software-
etaps-2022-munich-germany-april-27-2022-proceedings-ilya-
sergey-44887738
Programming 101 Learn To Code Using The Processing Programming
Language 2nd Edition 2nd Jeanine Meyer
https://ebookbell.com/product/programming-101-learn-to-code-using-the-
processing-programming-language-2nd-edition-2nd-jeanine-meyer-46238180
3. Programming 101 The How And Why Of Programming Revealed Using The
Processing Programming Language Jeanine Meyer
https://ebookbell.com/product/programming-101-the-how-and-why-of-
programming-revealed-using-the-processing-programming-language-
jeanine-meyer-46318424
Programming And Gui Fundamentals Tcltk For Electronic Design
Automation Suman Lata Tripathi
https://ebookbell.com/product/programming-and-gui-fundamentals-tcltk-
for-electronic-design-automation-suman-lata-tripathi-46318712
Programming With Openscad A Beginners Guide To Coding 3dprintable
Objects 1st Edition Justin Gohde
https://ebookbell.com/product/programming-with-openscad-a-beginners-
guide-to-coding-3dprintable-objects-1st-edition-justin-gohde-46410140
Programming In Two Semesters Using Python And Java Quentin Charatan
https://ebookbell.com/product/programming-in-two-semesters-using-
python-and-java-quentin-charatan-46494972
Programming The Future Politics Resistance And Utopia In Contemporary
Speculative Tv Sherryl Vint Jonathan Alexander
https://ebookbell.com/product/programming-the-future-politics-
resistance-and-utopia-in-contemporary-speculative-tv-sherryl-vint-
jonathan-alexander-46771488
12. xi
Foreword1
Whenever I talk to people about Flex 2, the most common questions they ask are the
basic ones: what is it, who is it for, and why did we build it? It turns out that
although these questions are basic, they really get to the heart of what Flex 2 is all
about.
Flex 2 is a new technology for building rich web applications and experiences that
run on Flash Player, so they look great, are responsive, and are highly interactive. It
was designed specifically to be comfortable and productive for those coming from a
web or application development background, though it is suitable for anyone.
Why did we build it? Well that’s a longer story.
This Shouldn’t Be Too Hard
The genesis of my involvement with Flex 2 really started with a seed of inspiration.
Like everyone who surfs the Web, I would occasionally come across an application
that just blew me away. It would be responsive, look incredible, and have an almost
cinematic quality to it. Being curious, I would poke around to figure out how it was
built.
What I discovered was that it was almost always built with Flash. Because my back-
ground is in software development and I like to build things, this made me want to
try Flash, so I did. The result was shocking and humbling. I failed miserably, and I
came away unable to fathom how anybody built anything with Flash, never mind
how they built the amazing creations that had inspired me.
Part of my problem was with the Flash authoring tool. Not only didn’t it feel like the
developer tools I’d used before, but also it didn’t really seem to have been designed
for what I was trying to do. For example, the Timeline is one of the most notable fea-
tures of Flash. I could not, for the life of me, figure out how I would use it to build an
application. Although developer tools often provide a toolbox of components, such
as buttons and lists that you can drag onto the design surface, the Flash toolbox was
13. xii | Foreword
different. Here the components were things such as a line, rectangle, pen, pencil, ink
bottle, and paint bucket. How do I build an application with a pencil?
The other problem I had was with the terminology used to describe the concepts pre-
sented by Flash Player. In Flash, small reusable UI elements are called Movie Clips.
The main display area is called the Stage. The output of compiling the project is a
Movie. I can’t tell you how weird it was to try to track down a problem by running
the Debug Movie command.
Maybe We Need a Different Approach
From my experiment, I concluded that Flash simply was not designed for building
applications, or for developers like me. However, rather than see this as a problem, I
saw it as an opportunity. How many more great Flash applications would there be if
it was easier for developers to build them?
I focused on this question, instead of just trying harder to use Flash, because my
main interest in software is not so much in writing applications, but in improving the
process of doing so. That is, I’ve been most concerned with what the code actually
looks like. As a result, I’ve spent most of my career working on application frame-
works and tools that simplify development.
My first framework was called zApp, and I began writing it in 1989. I had been
developing for Windows for three years, starting with version 1.03, and had grown
frustrated by how difficult it was. zApp not only made Windows development much
easier, but also solved another key problem for developers. It allowed you to move
your application to other platforms, such as OS/2 or Unix, simply by recompiling.
zApp was released in 1991 and it became a popular cross-platform application
framework.
During the mid-’90s, while working at Microsoft, I became more involved with web
applications and was amazed at how hard it was to write them. So, in 1997, a col-
league and I developed a prototype web development framework that we called XSP.
Based on the prototype’s success, I led a team to build a production version that we
shipped in 2002 as ASP.NET.
So, as I thought about Flash, I felt the same level of excitement that I had in those
previous projects, and I wanted to do something about it. Doing so would enable me
to simultaneously explore two areas that I loved: web application development and
rich, cross-platform UIs. Therefore, in mid-2004, I joined Macromedia to help make
Flash a great platform for developers.
14. Foreword | xiii
My First Meeting with Flex
At Macromedia, my first task was to learn about all of the projects underway that
were related to Flash, and it was then that I first heard about Flex. Version 1.0 had
been released a few months earlier, and it was described to me as a presentation
server for experienced Java developers building enterprise applications. When I
heard this and learned the price, which was very high, I realized why I had not previ-
ously noticed it. A high-priced enterprise server did not jump out at me as an easier
way to build Flash applications.
However, as I learned the details of how Flex actually worked, I began to become
more interested in it. The key thing Flex provided was a powerful, easy-to-use, devel-
oper-friendly framework for developing Flash applications. It also had a nice XML-
based language for defining the UI structure that ironically felt very similar to pro-
gramming in ASP.NET.
The server component of Flex provided two things. The first was the compiler that
translated all of the code into a SWF file for the Flash Player to run. The compile-on-
demand model was also very similar to how one built applications in ASP.NET.
However, unlike ASP.NET, the code you wrote ran on the client, not on the server.
So, the main question I had at this point was why is Flex a server? You don’t need a
server to compile, and it seemed to me that that would be much more easily done on
a developer’s machine.
There was one other server component of Flex, which was a gateway that enabled
Flash to talk to the server using an optimized binary protocol and integrated with
backend Java code. This was the one component of Flex that really needed to be a
server. However, it was used for only certain scenarios, and it really was optional. It
also was not addressing the fundamental problem I was looking to solve: namely,
making it easier and more intuitive for developers to build Flash applications.
Flex, Take 2
So, the biggest problem that I saw with Flex 1.0 was not with the technology per se,
but with the packaging and positioning. Selling Flex as an expensive enterprise server
made it irrelevant to developers who just wanted to build cool stuff in Flash. I just
could not imagine anyone who went through what I did with Flash saying, “Hmmm,
this isn’t really for me, maybe I’ll check out that multithousand-dollar enterprise pre-
sentation server.” As a result, an opportunity was missed, because I had become con-
vinced that if developers tried Flex, they would love it.
After I finished looking around, I made some recommendations as to what I thought
should be done. The first was that the part of Flex used to build Flash applications (i.
e., the Flex framework and compiler) should be offered separate from the server. I
had no problem with the server, as it had a lot of value, but it should not be required.
15. xiv | Foreword
I also recommended that we build a real developer-style tool for Flex that enabled a
more traditional client development model. Flex 1.0 did have a development tool,
called Flex Builder, but it was built as an extension to Dreamweaver and it lacked
many features one expected in a real developer IDE. What I wanted was something
that felt more like a tool such as Visual Studio or Eclipse.
The Flex 2 Framework
Fortunately, there was broad agreement, and my recommendations were reflected in
what we actually did to create Flex 2. So, what is it?
The core of Flex 2 is the Flex framework, a library of ActionScript objects that pro-
vide a great foundation for building rich Internet applications that run on Flash. It is
a developer-centric framework that provides a strong architecture and uses design
patterns that will be familiar to developers coming from a .NET, Java, or web devel-
opment background.
Flex 2 has a rich component model, similar to the ones found in Visual Basic, .NET,
and Java. Components expose properties to enable configuration, provide methods
to enable invoking their functionality, and fire events when their state changes. Flex
2 provides standard mechanisms for providing data to components, for customizing
their look and feel, and for managing their layout.
But Flex doesn’t just provide architecture. It also provides a wealth of useful compo-
nents so that developers don’t have to build everything from scratch. These include
buttons, lists, menus, sliders, tabs, accordions, data grids, and more. Of course, it is
easy to build your own components from scratch or customize the ones provided.
The primary way one programs with Flex is via a mix of ActionScript and an XML-
based language called MXML. Each tag in MXML maps to a component, so unlike
HTML, you don’t have a fixed set of tags. If you write new components, you have
new tags to use. Properties on a component become the tag’s attributes. MXML also
supports script blocks where you can put ActionScript event-handling code and util-
ity functions.
One exciting decision we made was to provide the Flex Framework SDK, which
includes the Flex framework with complete source, compilers, and other utilities, for
free. We did this to encourage adoption and enable it to be freely used with non-
Adobe tools. You can download it by going to the official Flex web site, http://www.
flex.org.
Flex Builder 2
Flex Builder 2 is an IDE that makes using the Flex framework more productive. It
provides a great code-editing environment for both ActionScript and MXML, a
16. Foreword | xv
WYSIWYG design view to allow you to build your UI visually, a powerful debugger,
and a project system that automates compiling your application.
The source editors are especially valuable because they help you to write correct code
more easily and they streamline learning the framework object model. We put a lot
of work into code completion to make it always up-to-date, whether it’s providing
suggestions for built-in classes or for ones that you create.
One of the challenges in doing this was that because MXML and ActionScript are
essentially two languages defining and using the same objects, what you do in one
affects the other. For example, you can define a class in ActionScript and use it from
MXML, and as you make changes to the class definition, they will be reflected in the
hints you are offered when editing MXML code.
Because we wanted to make Flex Builder a tool that developers would really like, we
built it on the Eclipse framework as a set of plug-ins. Eclipse is a widely adopted,
open source tools framework originally developed by IBM. It has a huge extension-
building community, and many of its extensions are free and open source and can
easily be integrated into Flex Builder 2. You can install Flex Builder as a standalone
tool, or as a set of plug-ins to an existing installation of Eclipse.
ActionScript 3
One of the most important aspects of Flex 2 is that it is written entirely in Action-
Script 3, which was introduced as part of Flash Player 9. Both products shipped
simultaneously. ActionScript 3 is an incredibly important new language for a num-
ber of reasons.
First, ActionScript has always been based on EcmaScript, which is the standard that
JavaScript is based on, but in the past was not implemented 100% to specification.
To better support the standard and help it move forward, Macromedia played an
active role on the EcmaScript planning committee and made ActionScript 100%
compatible with the next major revision of the standard.
One thing you’ll find is that this is not the JavaScript you have in today’s browsers,
but rather is a much more modern and robust language. In fact, I find it to be much
more like C# or Java and think it will really appeal to developers coming from either
of those languages. A key feature that I really like is the option of strong typing. This
results in much more useful error messages and enables you to produce much more
correct and reliable code.
To provide a more robust execution environment for ActionScript 3, the Flash Player
team developed a new virtual machine (VM), called ActionScript Virtual Machine 2,
or AVM2 for short. It was created from the ground up to be fast and scalable, and it
features a just-in-time (JIT) compiler that turns the ActionScript 3 bytecode into
native code. In that respect, it is much more like a Java VM or the .NET CLR than
the script engines in today’s browsers. The result is that it is 10 times faster than the
17. xvi | Foreword
previous VM and it uses much less memory. Note that the previous version of the
VM, now called AVM1, continues to be included within Flash Player to ensure back-
ward compatibility.
We recently made AVM2 open source by donating it to the Mozilla Foundation for
incorporation into Firefox. We believe this will speed adoption of the new standard,
and help ensure compatibility with future implementations of JavaScript.
Flex Data Services
The final component of Flex 2 is Flex Data Services (FDS), which represents the evo-
lution of the original Flex server. FDS has added an incredible array of features to
enable richer, more responsive applications, including client server messaging, JMS
integration, a rich data model and data synchronization framework, data paging, and
proxy services.
One of the most intriguing features is that FDS supports bidirectional messaging
between the client and the server. This allows the server to actually push data to the
client without the client having to poll for updates. This solves one of the key prob-
lems in building rich web applications for real-time data display, such as for finan-
cial services.
Although FDS is not always required when building a Flex application, it is
extremely valuable when it is required. To encourage easy adoption of FDS, we cre-
ated a free Express edition that allows free, nonexpiring commercial use. The only
limitation is that the applications can’t be clustered or run across multiple CPUs.
Taking Another Look at Flash
After joining Macromedia, I was able to take another look at Flash and spend more
time programming with it. This was important so that I could get a better under-
standing of how Flash developers work today. Over time, I was able to break
through some of the barriers I had initially encountered and began to understand
how Flash abstractions relate to those I was used to. As such, I gradually got the
hang of the fact that a Movie Clip is just another type of component.
I also had the opportunity to meet a number of the world’s top Flash developers,
which was really great, because they were the ones who inspired me to learn about
Flash in the first place. This was when I first met Chafic Kazoun and Joey Lott, the
authors of the book you hold in your hands.
One of the things that I found interesting is that today’s Flash developers are some-
what different from those in other communities. Some came to Flash from a creative
background, without prior software experience, and got into programming Flash in
order to enhance their work. Others came to Flash from a programming back-
ground, but were also interested in the aesthetic aspects of software. Whichever way
18. Foreword | xvii
they got there, however, they all had a mix of the creative and technical skills that is
not typical.
I do believe that Flex will change this somewhat, because you no longer have to have
great design skills to create something in Flash that looks fantastic. Flex applications
look great out of the box.
One of the things I have been delighted with is that Flex has been enthusiastically
received by Flash developers. One might have thought that they wouldn’t care
because they had already mastered the skills needed to use Flash, but they do care
and they like it. In fact, I recently spoke at some conferences, and the other Flex pre-
senters were almost all Flash developers who had gotten hooked on Flex.
In talking to them, I learned that they like that they can be more productive when
they’re building something that fits within the Flex paradigm. They find that the
architecture is well done and solves comprehensively what they used to address in an
ad hoc way. They love the fact that Flex Builder has a great coding environment. And
of course, they love that Flex and Flash can work together, so they can use each
where appropriate. Flex is not the right solution for everything they might want to
build, but when it is the right solution, they love it as much as anyone.
Programming Flex 2
One of the things that makes frameworks such as Flex so great is that they provide a
rich architecture and lots of prebuilt software components that enable you to build
software much more quickly than if you had to write it yourself. And the best frame-
works, of which Flex is one, allow you to deeply customize and extend the provided
functionality so that you are not limited in your creations.
With all of this, however, comes a degree of complexity. We put a ton of effort into
making sure that things are as consistent as possible, that the right design patterns
are used, and that there is the right balance of ease of use and flexibility, all in an
effort to make things as simple to learn and use as possible. With that said, there’s
nothing like a good book to take you through the concepts so that you can really
understand what’s going on.
What I really like about Programming Flex 2 is that not only does it take you through
the breadth of what Flex provides, but it also takes you deep into how it works. It
explains the high-level concepts as well as points out the finer details of what’s really
happening.
I also like that Programming Flex 2 takes a practical approach, explaining common
techniques of how ActionScript programs typically work in ways that go beyond sim-
ply explaining the classes that Flex provides.
Both Chafic Kazoun and Joey Lott are ideal people to present this information. Both
are long-time Flash developers, are well known in the Flash community, and are
19. xviii | Foreword
among the elite of the Flash development world. Each of them has been using Flex
for a long time.
I think that the depth of their Flash experience is part of what makes Programming
Flex 2 so special. Their mastery of the Flash Player API combined with their exten-
sive knowledge of Flex enable them to not just tell you how to leverage the features
Flex provides, but to do so with a thorough understanding of the entire system.
Looking Ahead
When we shipped Flex 2 June 27, 2006, it was just a few days shy of 18 months since
we had started developing it. It was a great accomplishment, because we built a new
tool from scratch, rewrote the framework in ActionScript 3, which was still being
developed, and shipped on schedule.
It was an amazing time, and a lot of fun. Of course, for us, probably the biggest thing
that happened was that Macromedia was acquired by Adobe Systems. Although
some Macromedia fans expressed concern that Adobe might not really support Flex,
they couldn’t have been more wrong. It was amazing to experience how excited
Adobe employees were about Flex and all of the technology being created by the
former Macromedia teams. And over the past year since the acquisition, this has
been confirmed by what we’ve been able to accomplish.
January 4, 2007, just six months after shipping Flex 2, we released Flex 2.0.1.
Although it sounds like a tiny update, it actually has a number of new features and
improvements. One of the key things that we were able to deliver was Flex Builder 2
for the Mac, running on both PowerPC and Intel.
We followed this up January 16 with Flash Player 9 for Linux. What makes this so
important is that it means you can now run Flex 2 applications that behave identi-
cally across Windows, the Mac, and Linux.
One of the most important extensions of what Flex can do is a project that was
begun immediately after Adobe and Macromedia combined. Apollo is a technology
that will allow developers to build desktop applications that run outside of the
browser using the web technologies they use today, including Flex/Flash, HTML/
AJAX, and PDF.
This means you can develop a Flex application and install it on either Windows or
the Mac (Linux will come a little later) and it will behave like any other application
on your system. On Windows, it can appear in the Start menu and in the taskbar,
and on the Mac, it will appear in the Doc. Apollo will have additional APIs that
enable you to interact with the system in ways you can’t from within the browser.
For example, you can open multiple windows, support drag and drop, and more
directly access the filesystem.
20. Foreword | xix
What’s more, you will be able to integrate full HTML into a Flex application. That
is, you’ll essentially be able to have the full HTML engine that powers the Mac Safari
browser embedded within your Flex app.
So, I think we are doing a number of exciting things to move Flex forward. How-
ever, I’m most looking forward to being inspired by the incredible apps that you cre-
ate with Flex 2. Good luck and happy coding!
—Mark Anders
Senior Principal Scientist,
Adobe Systems Incorporated
21. xxi
Preface2
This book is a long time in the making. We first started talking about this book sev-
eral years ago, when Flex 1.0 first hit the market. We recognized that Flex was some-
thing important, yet we knew the product hadn’t matured enough at that point.
However, we shortly thereafter heard the whispers of Flex 2, a new and improved
Flex. After working with Flex 2, we were certain that this was going to revolutionize
how we build applications. Running on a new virtual machine using new, stream-
lined metaphors, Flex 2 was light years ahead of anything we’d been working with to
develop rich Internet applications. It was at that point that we got serious about
writing this book.
You’ll learn shortly (starting in Chapter 1) what Flex 2 is and what you can do with
it. However, briefly, Flex 2 is a framework and a set of tools (e.g., compilers) for
building rich Internet applications. The framework is built on Flash Player technol-
ogy, and it leverages a new (and lightning-fast) virtual machine built into Flash Player
9. This means Flex 2 applications can utilize all the functionality of Flash Player,
such as animation, audio, video, request/response network data communication,
real-time data communication, and much more. Furthermore, the Flex 2 framework
vastly simplifies the creation of Flash Platform applications over previous options
(Flash authoring, Flex 1.5, etc.).
Flex 2 is huge. Although the learning curve is not steep (it’s actually very easy to get
started building Flex 2 applications), it is a long learning curve simply because of the
massive amount of features packed into the framework. The official Flex documenta-
tion is quite good at telling you how to do something once you know what you’re
looking for. Therefore, we made it our goal to present to you a book that fills in the
gaps and helps you to get comfortable enough with Flex that you start to quickly
know what you’re looking for. It is our intention in this book to provide you with
practical advice from our own experiences learning Flex and drawing from our
longer-term experiences building rich Internet applications using Flash Platform
technologies.
22. xxii | Preface
We really feel that Flex 2 is a fantastic product and a great way to build applications.
Although this is a technical book, we have poured our enthusiasm into our writing,
and we’d like to think you will share our enthusiasm as you read this book. We feel
that Flex 2 is a far better way to build rich Internet applications than any alternative
currently on the market, and we feel that as you read this book and learn how to
work with Flex, you’ll agree. With Flex, you have few (if any) problems involving
cross-browser compatibility, network data communication is a snap, and the frame-
work is built with solid object-oriented principals and standards in mind. In short,
we feel it’s the fastest way to build the coolest, most stable applications.
Who This Book Is For
This book is intended for anyone looking to learn more about Flex 2. We recognize
that the audience for this book represents a very diverse group of people with many
different backgrounds. Some readers may have years of experience working with
Flash Platform technologies, and others may be completely new to creating content
that runs in Flash Player. Some readers may have computer science degrees or have
worked in the software industry for years. Yet other readers may be self-taught. We
have done our best to write a book that will cater to this diverse group.
However, be aware that in order to get the most from this book, it is best that you
have a solid understanding of object-oriented principles, and that you are comfort-
able with understanding concepts such as runtime environments, byte code, and
compilers. Furthermore, you will get the most from this book if you already know
ActionScript, Java, C, C#, or another language that uses similar syntax. Although we
do have a chapter dedicated to the basics of ActionScript (the programming lan-
guage utilized by Flex applications), we don’t discuss any of the core APIs in detail. If
you are interested in learning more about the ActionScript language, we encourage
you to find a good ActionScript 3.0 book.
How This Book Is Organized
We spent a lot of time organizing and reorganizing the content of this book.
Although there is likely no one way to present the content that will seem perfect to
all readers, we’ve done our best to present it in an order that we feel will make sense.
Chapter 1, Introducing Flex
What is Flex? What are rich Internet applications (RIAs)? This chapter answers
these questions, providing a context for the rest of the book.
Chapter 2, Building Applications with the Flex Framework
In this chapter, we discuss the various elements and steps involved in building a
Flex application. Topics include using the compilers, building scripts, Flash
Player security, deploying applications, and more.
23. Preface | xxiii
Chapter 3, MXML
MXML is the declarative language used by Flex. In this chapter, you’ll learn the
basics of MXML.
Chapter 4, ActionScript
ActionScript is the object-oriented programming language used by Flex. In this
chapter, you’ll learn the basics of ActionScript 3.0.
Chapter 5, Framework Fundamentals
Flex vastly simplifies many aspects of building applications. Although you don’t
often have to look under the hood, understanding the fundamentals of how the
framework works is useful. In this chapter, you’ll learn about Flex application
life cycles, bootstrapping, and more.
Chapter 6, Managing Layout
Flex provides many layout containers that allow you to quickly and easily create
all sorts of layouts within your applications. This chapter explains how to work
with those containers.
Chapter 7, Working with UI Components
In this chapter, you’ll learn about the user interface components (buttons, lists,
menus, etc.) that are part of the Flex framework.
Chapter 8, Framework Utilities and Advanced Component Concepts
Once you’ve learned the basics of working with components, you’ll likely want
to know how to expand on that knowledge. In this chapter, you’ll learn about
such topics as tool tips, customizing lists, pop-up windows, and more.
Chapter 9, Working with Media
Flex allows you to include all sorts of assets and media in your applications,
from images to animations to video and audio. In this chapter, you’ll learn how
to work with these elements.
Chapter 10, Managing State
Flex applications and components within those applications can change from
one view to another. Flex refers to these changes as states. This is sometimes as
simple as adding a new component to a form, and it sometimes involves chang-
ing the entire contents of the screen. How to manage states is the subject of this
chapter.
Chapter 11, Using Effects and Transitions
For animated changes between states or in response to user events or system
events, Flex includes features called transitions and effects. You can learn about
transitions and effects in this chapter.
Chapter 12, Working with Data
In this chapter, you’ll learn how to model data in Flex applications as well as
how to link components so that they automatically update when data values
change.
24. xxiv | Preface
Chapter 13, Validating and Formatting Data
In this chapter, you’ll learn how to validate user input and how to format data
such as numbers, phone numbers, and so on.
Chapter 14, Customizing Application Appearance
Customizing the appearance of Flex applications is important because it allows
you to create applications that adhere to a corporate style guide or to a creative
vision. This chapter explains how to change the appearance of Flex applications.
Chapter 15, Client Data Communication
Client data communication is any transfer of data into or out of Flash Player
where the data remains on the client computer. Examples of this are communi-
cation between two or more Flex applications running on the same computer
and storing persistent data on the computer. These topics are discussed in this
chapter.
Chapter 16, Remote Data Communication
In this chapter, you’ll learn how to communicate from a Flex application run-
ning on a client computer to a remote data service. You’ll learn how to use XML,
SOAP, AMF, and more.
Chapter 17, Application Debugging
Debugging applications is just as important as writing them. It’s unusual to
build an application that has no errors, and therefore it’s crucial that you can
track down those errors efficiently. In this chapter, you’ll learn how to work
with the debugging features of Flex.
Chapter 18, Application Components
To make Flex application development manageable it’s important to know how
to break up the application into discrete parts. This chapter discusses strategies
for this.
Chapter 19, Building Custom Components
Custom components are an important part of Flex applications because they
allow you to create elements that can be used, customized, and distributed. This
chapter discusses the steps necessary to create custom components using the
Flex framework.
What You Need to Use This Book
In order to use this book, you should have the Flex SDK and a text editor. Our inten-
tion with this book is that anyone with the (free) SDK can follow along. However, we
recommend using Flex Builder for anyone serious about developing Flex applica-
tions. If you’re just starting with Flex, you might want to use the free trial version of
Flex Builder initially to have the optimal experience building Flex applications.
25. Preface | xxv
Conventions Used in This Book
The following typographical conventions are used in this book:
Italic
Indicates new terms, URLs, email addresses, filenames, file extensions, path-
names, directories, and Unix utilities.
Constant width
Indicates commands, options, switches, variables, attributes, keys, functions,
types, classes, namespaces, methods, modules, properties, parameters, values,
objects, events, event handlers, XML tags, HTML tags, macros, the contents of
files, or the output from commands.
Constant width bold
Shows commands or other text that should be typed literally by the user.
Constant width italic
Shows text that should be replaced with user-supplied values.
This icon signifies a tip, suggestion, or general note.
Using Code Examples
This book is here to help you get your job done. In general, you may use the code in
this book in your programs and documentation. You do not need to contact us for
permission unless you’re reproducing a significant portion of the code. For example,
writing a program that uses several chunks of code from this book does not require
permission. Selling or distributing a CD-ROM of examples from O’Reilly books does
require permission. Answering a question by citing this book and quoting example
code does not require permission. Incorporating a significant amount of example
code from this book into your product’s documentation does require permission.
We appreciate, but do not require, attribution. An attribution usually includes the
title, author, publisher, and ISBN. For example: “Programming Flex 2, by Chafic
Kazoun and Joey Lott. Copyright 2007 O’Reilly Media, Inc., 978-0-596-52689-4.”
If you feel your use of code examples falls outside fair use or the permission given
above, feel free to contact us at permissions@oreilly.com.
Comments and Questions
Please address comments and questions concerning this book to the publisher:
O’Reilly Media, Inc.
26. xxvi | Preface
1005 Gravenstein Highway North
Sebastopol, CA 95472
(800) 998-9938 (in the United States or Canada)
(707) 829-0515 (international or local)
(707) 829-0104 (fax)
We have a web page for this book, where we list errata, examples, and any addi-
tional information. You can access this page at:
http://www.oreilly.com/catalog/059652689X/
To comment or ask technical questions about this book, send email to:
bookquestions@oreilly.com
For more information about our books, conferences, Resource Centers, and the
O’Reilly Network, see our web site at:
http://www.oreilly.com
Acknowledgments
This book, perhaps more than most, represents the efforts and contributions of
many people. We’d like to acknowledge the following people.
Many thanks are due to the many people at O’Reilly who made this book possible.
Special thanks to Steve Weiss and Audrey Doyle for their continued hard work and
patience throughout the writing and editing of this book. They have each continu-
ously gone above and beyond the call of duty, and we very much appreciate their
efforts.
We’d also like to thank the many people at Adobe for not only working to create
such a fantastic product as Flex 2, but also for answering our questions and helping
us to see what things we might have missed. We’d especially like to thank a few
select people: Matt Chotin, Alex Harui, Andrew Spaulding, and Manish Jethani, who
not only answered our questions, but also took the time to review our chapters and
provide valuable comments. We’re also very grateful to Mark Anders from Adobe for
graciously accepting our invitation to write the Foreword to this book. We’re also
thankful for the help of Mike Chambers throughout the planning and writing of this
book.
The technical quality of this book is not just the work of the authors. The technical
reviewers for this book are a fantastic group of people who have dedicated hours and
hours of time to tell us when we’re wrong so that we can correct it before you can
read it. The technical reviewers are the reason the code in this book works. The tech-
nical reviewers for this book (in addition to the Adobe folks mentioned in the pre-
ceding paragraph) include: Darron Schall, Keith Peters, Marc Leuchner, Sam Roach,
Steven Schelter, Daniel Williams, Ben Stucki, Sam Neff, Eric Cancil, Larry David-
son, and Veronique Brossier.
27. Preface | xxvii
From Chafic
I would like to thank Joey Lott for being an excellent coauthor. His experience in
both the technical realm and the publishing industry helped me get through the long
process of writing this book. I would also like to thank my family, friends, and the
team at Atellis for their support through this experience; I made it! Finally, I would
like to thank the O’Reilly team for believing in a first-time author, and in this book.
From Joey
I would also like to thank a few people. This is Chafic’s book, and I am grateful that
he has trusted me enough to ask me to participate. Chafic has also pushed me to
ensure that I do my very best. I’d also like to thank Robert Reinhardt for his show of
faith in me all those years ago, giving me my first break in the writing business.
Thanks go to all my colleagues at Schematic for their willingness to help with reviews
and for asking all the right questions. Certainly I am grateful to my family and loved
ones for their support and generosity of spirit.
28. 1
Chapter 1 CHAPTER 1
Introducing Flex1
Flex is a collection of technologies that enables you to rapidly build applications
deployed to Flash Player, a runtime environment for delivering sophisticated user
interfaces and interactivity. Flex leverages existing, matured technologies and stan-
dards such as XML, web services, HTTP, Flash Player, and ActionScript. Even
though Flex allows you to create complete rich Internet applications, it does so in a
relatively simple and intuitive manner. While Flex does allow you to get under the
hood for more granular control over all the elements, it significantly lowers the learn-
ing curve in that it allows you to compose applications rapidly by assembling off-the-
shelf components, including UI controls, layout containers, data models, and data
communication components.
In this chapter, we’ll introduce Flex and Flex technologies in more detail so that you
can better understand what Flex is and how you can best get started working with it.
You’ll learn what elements a Flex application uses and how they work together.
We’ll also compare and contrast Flex with other technologies for creating both stan-
dard and rich Internet applications.
Understanding Flex Application Technologies
If you’re new to Flex, you may not yet have a clear understanding of what a Flex
application is, how it works, and what benefits it has over alternative technologies
and platforms. You build Flex applications utilizing the Flex framework, and you
deploy them using Flash Player. In the following sections, you’ll learn more about
Flash Player, the Flex framework, and additional technologies that may be part of a
Flex application.
Flash Player
Flex is part of the Adobe Flash Platform, which is a set of technologies with Flash
Player at the core. Flex applications are intended to be deployed to Flash Player,
29. 2 | Chapter 1: Introducing Flex
meaning Flash Player runs all Flex applications. With nearly every computer con-
nected to the Internet having some version of Flash Player installed, and an increas-
ing number of mobile devices being Flash-enabled, Flash Player is one of the most
ubiquitous pieces of software anywhere. Adobe estimates that each new version of
Flash Player has adoption rates reaching 80% in less than 12 months (Flash Player 8
reached 86% within 9 months). The reasons for such quick adoption rates are debat-
able, but there are a few factors that are almost certainly causative:
• Flash Player content is potentially more compelling and engaging than static
HTML content.
• Flash Player is capable of providing integrated solutions that utilize data ser-
vices, interactive UI design, media elements such as audio and video, and even
real-time communications.
• Well-made Flash Player content can provide a refreshing user experience that
utilizes metaphors from desktop computing, such as drag-and-drop and double-
click. Flash Player frees the UI design from scrolling pages of text and images.
• Flash Player is a relatively small (one-time) download. Even with the multitude
of new features added with every release, the Flash Player download is less than
1 MB. And with built-in features such as Express Install, upgrading Flash Player
versions is very simple.
• Stability and security are important considerations. Flash Player is a stable pro-
gram that has been around for nearly a decade. Adobe is very careful with Flash
Player security as well. Flash Player has very little access to the client’s local sys-
tem. It cannot save arbitrary files to the local system, and it cannot access Inter-
net resources unless they meet very strict requirements.
• Flash Player is cross-platform (and cross-browser) compatible. Flash Player runs
on Windows, OS X, and Linux, and on all major browsers, including Firefox,
Internet Explorer, Safari, and Opera.
Flex 2 content relies on features of Flash Player 9, meaning that users must be run-
ning Flash Player 9 or higher to correctly view Flex 2 content. You can read more
about deploying Flex applications and detecting player versions in Chapter 2.
Using the Flex framework you can build and compile to the .swf format. The com-
piled .swf file is an intermediate bytecode format that Flash Player can read. Flash
Player 9 introduces a new virtual machine called AVM2. AVM2 is written from the
ground up, and it functions in a fundamentally different way than previous ver-
sions of Flash Player. With AVM2, .swf content is no longer interpreted. Rather, it
is compiled (the equivalent of just-in-time compilation) and run such that it can
take advantage of lower-level computing power. This is very similar to how Java
and .NET applications work.
AVM2 brings the best of both worlds. Since .swf content is compiled to bytecode
that the ActionScript virtual machine can understand, the .swf format is platform-
independent. That also means that Flash Player ultimately dictates the functionality
30. Understanding Flex Application Technologies | 3
allowed by a Flex application. As mentioned previously, that means that Flash Player
can guarantee certain security safeguards so that you can deploy applications that
users can trust. Yet at the same time, AVM2 compiles the content so that it runs sig-
nificantly faster and more efficiently than previous versions of Flash Player.
The Flex Framework
The Flex framework is synonymous with the Flex class library and is a collection of
ActionScript classes used by Flex applications. The Flex framework is written
entirely in ActionScript classes, and defines controls, containers, and managers
designed to simplify building rich Internet applications.
The Flex class library is the subject of much of this book. It consists of the following
categories:
Form controls
Form controls are standard controls such as buttons, text inputs, text areas, lists,
radio buttons, checkboxes, and combo boxes. In addition to the standard form
controls familiar to most HTML developers, the Flex class library also includes
controls such as a rich text editor, a color selector, a date selector, and more.
Menu controls
Flex provides a set of menu controls such as pop-up menus and menu bars.
Media components
One of the hallmarks of Flex applications is rich media support. The Flex class
library provides a set of components for working with media such as images,
audio, and video.
Layout containers
Flex applications enable highly configurable screen layout. You can use the lay-
out containers to place contents within a screen and determine how they will
change over time or when the user changes the dimensions of Flash Player. With
a diverse set of container components you can create sophisticated layouts using
grids, forms, boxes, canvases, and more. You can place elements with absolute
or relative coordinates so that they can adjust correctly to different dimensions
within Flash Player.
Data components and data binding
Flex applications are generally distributed applications that make remote proce-
dure calls to data services residing on servers. The data components consist of
connectors that simplify the procedure calls, data models to hold the data that is
returned, and data binding functionality to automatically associate form control
data with data models.
31. 4 | Chapter 1: Introducing Flex
Formatters and validators
Data that is returned from remote procedure calls often needs to be formatted
before getting displayed to the user. The Flex class library includes a robust set
of formatting features (format a date in a variety of string representations, for-
mat a number with specific precision, format a number as a phone number
string, etc.) to accomplish that task. Likewise, when sending data to a data ser-
vice from user input, you’ll frequently need to validate the data beforehand to
ensure it is in the correct form. The Flex class library includes a set of validators
for just that purpose.
Cursor management
Unlike traditional web applications, Flex applications are stateful, and they
don’t have to do a complete screen refresh each time data is sent or requested
from a data service. However, since remote procedure calls often incur network
and system latency, it’s important to notify the user when the client is waiting on
a response from the data service. Cursor management enables Flex applications
to change the cursor appearance in order to notify the user of such changes.
State management
A Flex application will frequently require many state changes. For example,
standard operations such as registering for a new account or making a purchase
usually require several screens. The Flex class library provides classes for manag-
ing those changes in state. State management works not only at the macro level
for screen changes, but also at the micro level for state changes within individ-
ual components. For example, a product display component could have several
states: a base state displaying just an image and a name, and a details state that
adds a description, price, and shipping availability. Furthermore, Flex provides
the ability to easily apply transitions so that state changes are animated.
Effects
Flex applications aren’t limited by the constraints of traditional web applica-
tions. Since Flex applications run within Flash Player, they can utilize the anima-
tion features of Flash. As such, the Flex class library enables an assortment of
effects such as fades, zooms, blurs, and glows.
History management
As states change within a Flex application, the history management features of
the Flex class library enable you to navigate from state to state using the back
and forward buttons of the web browser.
Drag and drop management
The Flex class library simplifies adding drag and drop functionality to compo-
nents with built-in drag and drop functionality on select components and a man-
ager class that allows you to quickly add drag and drop behaviors to components.
32. Understanding Flex Application Technologies | 5
Tool tips
Use this feature of the Flex class library to add tool tips to elements as the user
moves the mouse over them.
Style management
The Flex class library enables a great deal of control over how nearly every
aspect of a Flex application is styled. You can apply style changes such as color
and font settings to most controls and containers directly to the objects or via
CSS.
Flex Builder 2
Flex Builder 2 is the official Adobe IDE for building and debugging Flex applica-
tions. Built on the popular Eclipse IDE, Flex Builder has built-in tools for writing,
debugging, and building applications using Flex technologies such as MXML and
ActionScript.
The Flex framework ships as part of Flex Builder. However, Flex Builder and the
Flex framework are not synonymous. You do not have to use Flex Builder to use the
Flex framework. Instead, you can opt to install the free Flex SDK, which includes the
compiler and the Flex framework. You can then integrate the Flex framework with a
different IDE, or you can use any text editor to edit the MXML and ActionScript
files, and you can run the compiler from the command line.
Flex Builder is a commercial product. See http://www.adobe.com/go/
flexbuilder for more information.
Integrating with Data Services
Data services are an important aspect of most Flex applications. They are the way in
which the Flex application can load and send data originating from a data tier such
as a database (we discuss the concept of tiers in the section “Understanding the Dif-
ferences Between Traditional (HTML) and Flex Web Applications” later in this
chapter). Flash Player supports any text data, XML, a binary messaging format called
AMF, and persistent socket connections, allowing for real-time data pushed from the
server to the client.
Each data format Flex supports may or may not require special server resources. For
example, a Flex application can request XML data from a static resource or from a
dynamic resource such as a PHP page. AMF is a binary messaging format that Flash
Player understands natively, but for a server to interact with Flash Player via AMF, it
requires an AMF translator on the server, such as the remote object services that are
part of Flex Data Services.
33. 6 | Chapter 1: Introducing Flex
Flex simplifies working with data services by way of classes and components that are
part of the framework. Working with data services is discussed in more detail in
Chapter 14.
Integrating with Media Servers
Since Flex applications are deployed using Flash Player, they can leverage the media
support for Flash video and audio. Although Flash Player can play back Flash video
and MP3 audio as progressive downloads, you can benefit from true streaming
media by way of a technology such as Flash Media Server.
Additional Flex Libraries and Components
At the time of this writing there is just one official add-on Flex library, the Flex
Charting Components. As time goes on, it is expected that many additional Flex
libraries will become available. Additional Flex libraries such as the Flex Charting
Components are not part of the standard component sets that ship with the Flex
framework. Rather, you must acquire the software and licenses, and add them to the
Flex classpath. Add-on libraries enable more rapid application development because
they provide prebuilt functionality. For example, with the addition of the charting
component set, you can quickly and simply add robust charting and graphing fea-
tures to Flex applications.
You can find many extensions, such as Flex libraries and components,
at the Adobe Exchange (http://www.adobe.com/exchange).
Using Flex Elements
The Flex framework includes a core set of languages and libraries that are the basis
of any Flex application. Using MXML, ActionScript, and the Flex class library you
can construct and compile .swf content that you can then deploy to Flash Player.
MXML
MXML is an XML-based markup language that primarily describes screen layout. In
that respect it is much like HTML. Using MXML tags, you can add components such
as form controls and media playback components to layout containers such as grids.
In addition to screen layout, you can use MXML to describe effects, transitions, data
models, and data binding. MXML is robust enough that it is possible to build many
applications entirely with MXML. Flex Builder enables you to construct MXML with
a WYSIWYG approach, which allows you to build basic Flex applications without
writing any code.
34. Working with Data Services (Loading Data at Runtime) | 7
While the WYSIWYG approach is helpful for basic prototypes and simple applica-
tions, writing MXML code is still necessary for more complex tasks. Additionally,
sophisticated Flex applications generally require both MXML and ActionScript.
MXML is a declarative way to create Flex content, but the simplicity should not fool
you into thinking that MXML is not powerful. MXML provides a fast and powerful
way to create layout and UI content. However, MXML documents get compiled in
several steps, the first of which converts the MXML to an ActionScript class. This
means that MXML documents provide you with all the power of object-oriented
design, but with the convenience of a markup language. Furthermore, MXML docu-
ments are treated as ActionScript classes at runtime.
ActionScript
ActionScript is the programming language understood by Flash Player and is the fun-
damental engine of all Flex applications. MXML simplifies screen layout and many
basic tasks, but all of what MXML does is made possible by ActionScript, and
ActionScript can do many things that MXML cannot do. For example, you need
ActionScript to respond to events such as mouse clicks.
Although it is possible to build an application entirely with MXML or entirely with
ActionScript, it is more common and more sensible to build applications with the
appropriate balance of both MXML and ActionScript. Each offers benefits, and they
work well together. MXML is best suited for screen layout and basic data features.
ActionScript is best suited for user interaction, complex data functionality, and any
custom functionality not included in the Flex class library.
ActionScript is supported natively by Flash Player, and does not require any addi-
tional libraries to run. All the native ActionScript classes are packaged in the flash
package or in the top-level package. In contrast, the Flex framework is written in
ActionScript, but those classes are included in a .swf file at compile time. All the Flex
framework classes are in the mx package.
Working with Data Services (Loading Data at Runtime)
Flex applications are generally distributed applications. That means that several
computers work in conjunction to create one system. For example, all Flex applica-
tions have a client tier (discussed shortly) that runs on the user’s computer in the
form of a .swf running in Flash Player. In most cases, the client tier communicates
with a server or servers in order to send and retrieve data. The servers provide what
are called data services, which are essentially programs that have public interfaces
(APIs) whereby a client can make a request to a method of that program. When a cli-
ent makes such a request, it is called a remote procedure call, or RPC.
There are many types of data services. In its simplest form a data service could con-
sist of a static text file or XML document served from a web server. A slightly more
35. 8 | Chapter 1: Introducing Flex
sophisticated data service might be a dynamic XML document generated via a server-
side script or program, such as a PHP or ASPX page. Many data services require
greater sophistication. One of the most common types of such a sophisticated data
service is the web service. Web services use XML (generally in the form of SOAP) as a
messaging format, and they enable RPCs using the HTTP protocol for requests and
responses. Although a SOAP web service is an example of a standards-based data
service, many types of data services don’t necessarily conform to a particular stan-
dard set by the W3C. Many programs on the Web, for example, expose primitive
data services that use arbitrary messaging formats and protocols. One such program
is used by MapQuest, a popular mapping web site. For instance, you would use the
following URL to view a MapQuest page with a map of Los Angeles:
http://www.mapquest.com/maps/map.adp?country=US&city=Los+Angeles&state=CA
Notice that the query string uses arbitrary parameters to determine what to map.
Therefore, if you wanted to display a map of New York, you would change the city
and state parameter values in the URL as follows:
http://www.mapquest.com/maps/map.adp?country=US&city=New+York&state=NY
Flash Player is capable of making RPCs to many types of data services. For example,
Flash Player can make requests to any web resource using HTTP, which means it can
make requests to many primitive data services such as a static or a dynamic XML
document, or the MapQuest example mentioned previously. That also means it can
make requests to web services. Moreover, the Flex class library simplifies requests to
most data services.
In addition to the types of data services previously mentioned, Flex applications can
also make calls to methods of classes on the server, using a technology called Flash
Remoting. Flash Remoting uses the AMF binary messaging format, which is sup-
ported natively by Flash Player. AMF has all the benefits of SOAP, but since it is
binary, the bandwidth overhead is greatly reduced. And since AMF is natively sup-
ported by Flash Player, no special coding is necessary to use Flash Remoting data ser-
vices from the client tier. However, for a Flash Remoting data service to be available
to the client tier, it must be made accessible via a piece of software that resides on the
server, and can read and write AMF packets and delegate the requests to the correct
services. Flex Data Services provides an implementation of Flash Remoting that inte-
grates easily with components in the Flex framework. That means that if you use
Flex Data Services, you can quickly configure applications to utilize Flash Remoting
without writing ActionScript. However, you’re not locked into using Flex Data Ser-
vices in order to use Flash Remoting. There are many Flash Remoting server prod-
ucts, including open source options such as OpenAMF (http://www.openamf.org)
and AMFPHP (http://www.amfphp.org).
36. Understanding the Differences Between Traditional (HTML) and Flex Web Applications | 9
Understanding the Differences Between Traditional
(HTML) and Flex Web Applications
Many applications deployed on the Web use an HTML user interface. Flex applica-
tions are similar in many respects, but they have distinct differences. If you’re used to
building applications that use an HTML UI, it’s important to take a few moments to
shift how you approach building applications when you start working with Flex.
What works for HTML-based applications may or may not work for Flex
applications.
Both traditional and Flex applications are generally n-tiered. The exact number and
types of tiers an application has depend on many factors. Most traditional applica-
tions have, at a minimum, a data tier, a business tier, and a presentation tier. Flex
applications have a data tier and a business tier; however, as noted earlier, they also
introduce a client tier, which is what strongly differentiates them from traditional
web applications. The client tier of Flex applications enables clients to offload com-
putation from the server, freeing up network latency and making for responsive and
highly interactive user interfaces.
Data tiers generally consist of databases or similar resources. Business tiers consist of
the core application business logic. As an example, a business tier may accept
requests from a client or presentation tier, query the data tier, and return the
requested data.
In traditional applications the presentation tier consists of HTML, CSS, JavaScript,
JSP, ASP, PHP, or similar documents. Typically a request is made from the user’s
web browser for a specific presentation tier resource, and the web server runs any
necessary interpreters to convert the resource to HTML and JavaScript, which is then
returned to the web browser running on the client computer. Technically the HTML
rendered in the browser is a client tier in a traditional web application. However,
since the client tier of a traditional web application is stateless and fairly nonrespon-
sive, it is generally not considered a full-fledged tier. (The exception to that generali-
zation is the case of Ajax applications, which use client-side JavaScript and XML to
build responsive and sophisticated client tiers.)
Flex applications generally reside embedded within the presentation tier. In addi-
tion, Flex applications can integrate with the presentation tier to create tightly cou-
pled client-side systems. Flex applications use Flash Player to run sophisticated
client-tier portions of the application. The Flex application client is stateful, which
means that it can make changes to the view without having to make a request to the
server. Furthermore, the Flex application client is responsive. For example, Flash
Player can respond to user interaction such as mouse movement, mouse clicks, and
keyboard presses, and it can respond to events such as notifications from the busi-
ness tier when data is returned or pushed to the client. Flash Player also can respond
to timer events. Since Flash Player is a smart client, it is capable of saving on network
37. 10 | Chapter 1: Introducing Flex
overhead and bandwidth usage by managing client-side logic without having to con-
sult the business tier. For example, Flex applications can walk the user through a
step-based or wizard-like interface, collect and validate data, and allow the user to
update and edit previous steps, all without having to make requests to the business
tier until the user wants to submit the data. All this makes Flex clients potentially far
more compelling, responsive, and engaging than traditional web applications.
Because the Flex application client tier is so much more sophisticated than the pre-
sentation tier of a traditional web application, the Flex client tier requires signifi-
cantly more time and resources to build successfully. A common mistake is to
assume that Flex client tiers require the same time and resources as a traditional web
application presentation tier. Successful Flex client tiers often require the same time
and resources during design, implementation, and testing phases as the business tier.
Understanding How Flex Applications Work
Flex applications deployed on the Web work differently than HTML-based applica-
tions. It’s important to understand how Flex applications work in order to build
them most effectively. When you understand how Flex applications work, you can
know what elements are necessary for an application and how to build the applica-
tion for the best user experience. Figure 1-1 summarizes the basic concepts dis-
cussed in this section.
Every Flex application deployed on the Web utilizes Flash Player as the deployment
platform. That means that a fundamental understanding of Flash Player is essential
to understanding Flex. Additionally, all Flex applications use the Flex framework at a
minimum to compile the application. As such, it’s important to understand the rela-
tionship between the source code files, the compiler, and Flash Player.
All Flex applications require at least one MXML file or ActionScript class file, and
most Flex applications utilize both MXML and ActionScript files. The MXML and
ActionScript class files comprise the source code files for the application. Flash
Figure 1-1. Understanding Flex application source-compile-deploy workflow
Source Code Gen Flash Player
ActionScript3
MXML
Assets
(PNG,Gif,etc.)
AVM2
Bytecode
+
Assets
ActionScript
+
Generated
ActionScript
Assets
(PNG,Gif,etc.)
38. Understanding Flex and Flash Authoring | 11
Player does not know how to interpret MXML or uncompiled ActionScript class
files. Instead, it is necessary to compile the source code files to the .swf format, which
Flash Player can interpret. A typical Flex application compiles to just one .swf file.
You then deploy that one .swf to the server, and when requested, it plays back in
Flash Player. That means that unlike HTML-based applications, the source code files
remain on the development machine, and you do not deploy them to the production
server.
Asset files such as MP3s, CSS documents, and PNGs can be embedded within a .swf,
or they can be loaded at runtime. When an asset is embedded within a .swf, it is not
necessary to deploy the file to the production server, because it is compiled within
the .swf file. However, since embedding assets within the .swf often makes for a less
streamlined downloading experience and a less dynamic application, it is far more
common to load such assets at runtime. That means that the asset files are not com-
piled into the .swf, and much like an HTML page, the assets are loaded into Flash
Player when requested by the .swf at runtime. In that case, the asset files must be
deployed to a valid URL when the .swf is deployed.
Data services are requested at runtime. That means that the services must be avail-
able at a valid URL when requested at runtime. For example, if a Flex application
utilizes a web service, that web service must be accessible from the client when
requested. Media servers and Flex Enterprise Services must also be accessible when
used by Flex applications.
Understanding Flex and Flash Authoring
Many developers first learning about Flex 2 may still be unclear as to the relation-
ship between Flex and Flash authoring, the traditional tool for creating content for
Flash Player. First, you do not have to understand Flash authoring in order to work
with Flex. In fact, you can get started with Flex without any prior knowledge of or
experience in Flash authoring.
Flash authoring is a product that was first created in 1996 as a vector animation tool
primarily aimed at creating animation content for the Web. In the many versions
since that time, both Flash authoring and Flash Player (the deployment platform for
Flash authoring content) have enabled greater and greater capabilities, and develop-
ers began to create rich Internet applications with the tools. However, while Flash
authoring is a fantastic tool for creating animations, it is not the ideal tool for creat-
ing applications. The metaphors that Flash authoring uses at its core (such as time-
lines) are simply not applicable to application development.
Flex 2 is a product aimed primarily at creating applications. The framework includes
a rich set of layout and user interface components, and the technology uses meta-
phors such as states and transitions that are appropriate to application development.
39. 12 | Chapter 1: Introducing Flex
Both Flex and Flash authoring allow you to create .swf content that runs in Flash
Player. In theory you can achieve the same things using both products. However,
Flash is a tool that allows you to create timeline-based animations and to use draw-
ing tools best suited for expressiveness, while Flex allows you to much more rapidly
assemble screens of content with transitions and data communication behaviors. As
with any craft, it is advisable to use the best tool for the job. Up until now, Flash
authoring was one of the only tools for creating .swf content. But with Flex 2, we
now have a tool with a more specific focus.
Although many people may initially try to frame the Flex and Flash authoring debate
as a winner-takes-all scenario, it is rather naive to think of them as competing tech-
nologies. Rather, they are two complementary technologies that allow all Flash plat-
form developers to utilize specialized tools when creating rich Internet content. In
fact, Flex and Flash authoring can work very well together. As you’ll see in this book,
Flex can import content created in Flash authoring, allowing you to create rich Inter-
net applications that use timeline-based content.
Understanding Flex 1.5 and Flex 2
If you are familiar with earlier versions of Flex (Flex 1 and Flex 1.5), you may be
interested in the relationship between Flex 2 and those earlier versions. While Flex
2 continues to utilize MXML and ActionScript (both supported in earlier versions
of Flex), it is vastly different from Flex 1 and Flex 1.5 in other respects. Flex 2
allows you to compile and deploy independent .swf files without any sort of expen-
sive server-side services as was required by Flex 1 and 1.5 (though the ability to
compile .swf files on the server at request time is still available in Flex Data Ser-
vices). Flex 2 requires Flash Player 9, which allows for (and requires) the use of
ActionScript 3. This latest ActionScript version introduces significant changes to
the Flash Player API that offers a much improved way to add and remove display
objects (including components) to the view.
Summary
In this chapter, we introduced the basics of what Flex is and what technologies and
products are used to create Flex applications. You learned that Flex 2 consists of a
framework (a class library) and a compiler that allow you to rapidly create Flex appli-
cations. These applications are .swf files, which you can then run in Flash Player 9.
40. 13
Chapter 2 CHAPTER 2
Building Applications with the Flex
Framework2
The majority of this book is dedicated to programming Flex applications, with
detailed discussions of working with MXML and ActionScript. However, in order to
meaningfully use most of what we discuss in the chapters that follow, you’ll need to
know how to create a Flex project, how to compile the project, and how to deploy
that project so that you can view it.
In this chapter we’ll discuss important topics such as the tools required for creating
Flex applications and how to create new projects for Flex applications. We’ll look at
the elements comprising a Flex project and discuss compiling and deploying Flex
applications.
Using Flex Tool Sets
In order to work with Flex and build Flex applications, you’ll need tools. At a mini-
mum you must have a compiler capable of converting all your source files and assets
into the formats necessary to deploy the application. That means you need to be able
to compile MXML and ActionScript files into a .swf file.
There are two primary tools you can use that include the necessary compilers:
• The Flex SDK (Software Development Kit)
• Flex Builder 2
The Flex SDK is a free product that includes the entire Flex framework as well as the
mxmlc and compc compilers (see the section “Building Applications” later in this chap-
ter, for more details on the compilers). You can download the SDK at http://www.
adobe.com/products/flex/sdk.
Flex Builder 2 is a commercial product designed to work with Flex, and it too
includes the mxmlx and compc compilers. You can download a trial version of Flex
Builder 2 or purchase a license at http://www.adobe.com/go/flexbuilder.
41. 14 | Chapter 2: Building Applications with the Flex Framework
Flex Builder includes the entire SDK.
You can work with Flex Builder 2 in two ways: standalone and as a plug-in for
Eclipse (http://www.eclipse.org). The standalone version of Flex Builder 2 is built on
Eclipse, so it and the plug-in version are essentially equivalent. The primary
differences are:
• Flex Builder 2 standalone does not require that you already have Eclipse
installed, making it an optimal solution for those who have no other use for
Eclipse. On the other hand, if you already use Eclipse, or if you intend to use
Eclipse for other purposes, the standalone version would essentially require you
to have two installations of Eclipse—one running Flex Builder and one standard
installation. If you use or plan to use Eclipse for other reasons you should defi-
nitely install the plug-in version of Flex Builder 2.
• The standalone version disables Java Development Tools (JDT), a plug-in used
by some standard Eclipse features such as Ant (http://ant.apache.org). If you
want to use JDT, you should install the plug-in version of Flex Builder 2.
Since Flex Builder is built on Eclipse, you can use any third-party
Eclipse plug-ins with the standalone version of Flex Builder.
Many factors might drive your decision as to whether to use the Flex SDK or Flex
Builder 2. The following is a list of just a few to consider:
Price
The Flex SDK is a free product. It includes the entire Flex framework. Flex
Builder 2, on the other hand, is a commercial product. There is no difference in
the price between the standalone and plug-in versions of Flex Builder 2.
Commitment to an existing IDE
If you already have a considerable investment in an IDE in terms of time and
resources, and if that IDE works very well for you, you may want to integrate the
Flex SDK with your existing IDE. On the other hand, if you’re already using
Eclipse, consider that you can install the Flex Builder 2 plug-in for an existing
installation of Eclipse.
42. Creating Projects | 15
Debugging capabilities
The Flex SDK includes a command-line debugger. However, Flex Builder 2
includes an integrated debugger that allows you to set breakpoints and step
through code, all from within your IDE.
Efficiency
Unless and until other IDEs have increased support for Flex (ActionScript and
MXML), Flex Builder is the fastest way to build Flex applications. With its built-
in code hinting, code completion, error detection, and debugging capabilities,
Flex Builder is far superior to the SDK for serious Flex application developers.
The majority of the content of this book is not dependent on any one tool. Much of
our focus is on working with the Flex framework and ActionScript 3.0 and will
require only the Flex SDK. When there are specific topics that do have dependencies
on a particular tool, we make that clear. For example, in this chapter we discuss the
differences between configuring a Flex Builder project versus a Flex SDK project.
Creating Projects
A Flex application consists of potentially many files. Although it’s possible that a
Flex project could consist of as little as one source file, most use tens if not hundreds
of files. A typical Flex project might utilize the following:
MXML files
These files contain the majority of the application view—the layout and UI com-
ponents. You can read an introduction to MXML in Chapter 3. You can also
learn about application and MXML components (both written in MXML) in
Chapter 18.
ActionScript classes
These files contain the source code for all the custom components, data models,
client-side business logic, and server proxies. You’ll find an introduction to
ActionScript in Chapter 4.
XML files
Although XML is frequently loaded from a server as a dynamic response to an
HTTP request from Flash Player, many applications also utilize static XML files
as configuration parameters.
Image files
Flex applications can embed image files or load them at runtime. Working with
images is covered in Chapter 9.
Audio and video files
Flex applications can load audio and video content for playback within the
application. Audio and video are almost always loaded at runtime. Audio and
video are also discussed in Chapter 9.
43. 16 | Chapter 2: Building Applications with the Flex Framework
Runtime shared libraries
Runtime shared libraries are .swf files that contain code libraries that are shared
between two or more Flex applications deployed on the same domain. In order
to utilize a runtime shared library, you need two files: a .swf and a .swc. The .swf
file contains the libraries, and the .swc file is used by the compiler to determine
which libraries to exclude from the application .swf. Runtime shared libraries are
discussed in more detail later in this chapter, in the section titled “Using
Runtime Shared Libraries.”
HTML wrapper file
Flex applications are typically deployed on the Web. The published application
is a .swf file. The most common way to playback a .swf on the Web is to embed
it in an HTML page. The HTML wrapper file is the file that embeds the .swf.
Setting Up a New Project
How you configure a new Flex project depends in large part on what tool set you are
using. If you’re using the Flex SDK, that tool set generally requires the most work in
order to configure a new project.
Creating an SDK project
Presumably if you are using the Flex SDK, you are integrating it with an IDE such as
Eclipse (http://www.eclipse.org), PrimalScript (http://www.sapien.com), or FlashDe-
velop (http://www.osflash.org/flashdevelop). If you are indeed using an IDE, you most
likely want to start a new project (or workspace or whatever particular terminology
your IDE uses). If you are not using an IDE (you like to edit code using a plain-text
editor), you will want to create a new directory for the project.
You’ll place all the project files in the project directory, likely organizing them into
subdirectories. Which subdirectory structure you use is ultimately up to you. You’ll
need to know where and how you’re organizing all the source code and assets so that
you can configure the appropriate compiler options when building the application.
(Compiler options are discussed in the next section, “Building Applications.”) Files
typically are organized into the following directories:
src
A directory containing all the source MXML and ActionScript class files. The
files are then generally organized into packages. You can organize both MXML
and ActionScript files into packages in a Flex project. Packages are discussed in
more detail in Chapters 3 and 4.
bin
A directory to which you save the compiled version of the application.
html
A directory in which you keep the HTML wrapper file(s).
44. Creating Projects | 17
assets
A directory in which you save all the asset files used by the application either at
compile time or at runtime.
build
A directory in which you can place build scripts if using Apache Ant.
Creating a Flex Builder 2 project
Using Flex Builder 2, you can create a new project with a few clicks on the mouse.
From the Flex Builder 2 menus you can select File ➝ New ➝ Flex Project. This opens
the Flex Project dialog which walks you through a short wizard comprising the
following steps:
1. The first step asks you to select how the application will access data. Unless we
specify otherwise, all the examples we provide in this book will work via the
Basic option. See Figure 2-1.
2. The second step asks you to name the project. You can also specify a nondefault
location for the new project directory. See Figure 2-2.
3. At the completion of step 2, you can click Finish. If you click Next, you’ll see a
third step asking you to customize the source path and library path. These set-
Figure 2-1. Specifying how the application will access data
45. 18 | Chapter 2: Building Applications with the Flex Framework
tings specify classes and libraries that you want to use but that reside outside of
the project directory or in a nonstandard location within the project directory.
Unless stated otherwise, no examples in this book require you to customize the
source path or library path. See Figure 2-3.
Normally Flex Builder assumes that the main source directory is syn-
onymous with the project directory. However, when you create a
project that points to an existing directory, you may occasionally want
to point to a directory that is a parent of the directory containing the
main source files. In such cases you should be sure to set the Main
source folder option in step 3 of the new project wizard, as shown in
Figure 2-3.
When you create a Flex Builder project, you’ll see that the new directory has a bin
directory to which Flex Builder saves the compiled application by default, as well as
an html-template directory which stores the templates used by Flex Builder to gener-
ate the HTML wrapper file. You’ll also see that new Flex Builder Flex projects auto-
matically create an MXML document with the same name as the project.
Figure 2-2. Naming the project and specifying a location for the new project directory
46. Building Applications | 19
Building Applications
Once you’ve created a project and written some code, you’ll want to build the
project, which means compiling it and deploying it. How you accomplish these tasks
depends, in part, on what tools you’re using. The following subsections discuss how
to compile using the mxmlc compiler. If you’re using Flex Builder 2, you may want to
skip directly to the section “Compiling Using Flex Builder” later in this chapter.
Figure 2-3. Setting the build paths for the new Flex project
47. 20 | Chapter 2: Building Applications with the Flex Framework
Compiling Using mxmlc
The mxmlc compiler is used to compile Flex applications (versus compc, which is used
to compile components and libraries). When you use Flex Builder to compile, it
automatically calls mxmlc (Flex Builder includes the SDK).
There are several ways you can use mxmlc, including from the command line, from a
.bat or shell script, from an IDE, and from Apache Ant. Initially we’ll look at using
mxmlc from the command line since it’s the most basic way to use the compiler
(though we’ll also look at using the compiler via Apache Ant later in this chapter).
All the compiler flags we’ll look at from the command line also apply to any other
use of the compiler.
When you want to work with mxmlc from the command line, it’s generally a good
idea to make sure you add it to your system path. If you’re running Windows and
you’re uncertain how to edit your system path, follow these steps:
1. Right-click on My Computer from the desktop or from the Start menu, and
select Properties.
2. Click on the Advanced tab, and then click the Environment Variables button.
3. In the System Variables list in the bottom part of the dialog, scroll until you see a
variable called Path. Then edit the variable either by double-clicking on it or by
selecting it and then clicking the Edit button.
4. At the end of the existing value, add the path to the Flex SDK’s bin directory. If
you’re using Flex Builder, the default location is C:Program FilesAdobeFlex
Builder 2Flex SDK 2bin. If you’re using the SDK and you installed the SDK in
C:FlexSDK, the location is C:FlexSDKbin. Windows uses a semicolon (;) as a
delimiter. If necessary, add a semicolon between the existing value and the new
addition.
5. Click OK on each open dialog.
For OS X and Linux you’ll want to set the PATH environment variable in your shell.
If you are using .bash or any shell that supports .profile files, you will want to add a
.profile file in your user directory (or edit the file if it already exists). You can edit
the file with any text editor that you want. If you are familiar with vi, for example,
you can simply open a Terminal and type vi ~/.profile. The .profile should con-
tain a line such as the following:
export PATH=$PATH:/Users/username/FlexSDK/bin
The preceding assumes that you have installed the SDK in your user directory (you’ll
need to change username to your actual username). If you’ve installed the SDK else-
where you should modify the path correspondingly. Also note that the preceding
assumes that you don’t want to add additional directories to your path. If you have
an existing .profile file that already contains an export PATH line, you should simply
append the Flex bin path to that line using a colon (:) as a delimiter. For example:
export PATH=$PATH:/existing/directories:/Users/username/FlexSDK/bin
48. Building Applications | 21
Once you’ve edited the .profile you’ll need to run the following command from any
existing Terminal windows or command prompts:
source ~/.profile
To use the compiler from the command line you simply specify the compiler name
followed by the options. The only required option is called file-specs, and it allows
you to specify the entry point to the application you want to compile, i.e., the main
MXML document (or ActionScript class):
mxmlc -file-specs SampleApplication.mxml
Notice that file-specs is preceded by a hyphen. All options are preceded by a
hyphen.
You can get help for the compiler by running mxmlc with the help
option:
mxmlc -help
The file-specs option is the default option for mxmlc. That means a value that is not
preceded by an option flag will be interpreted as the value for file-specs. The fol-
lowing example is equivalent to the preceding example:
mxmlc SampleApplication.mxml
Each of the following examples attempts to compile SampleApplication.mxml to
SampleApplication.swf.
Specifying an output location
By default, mxmlc compiles the application to a .swf with the same name as the input
file (i.e., SampleApplication.mxml compiles to SampleApplication.swf ) in the same
directory as the input file. However, you can specify an output path using the output
option. The following compiles SampleApplication.mxml to bin/main.swf:
mxmlc SampleApplication.mxml -output bin/main.swf
Specifying source paths
The source path is the path in which the compiler looks for required MXML and
ActionScript files. By default, the compiler looks in the same directory as the com-
pile target (the file specified by file-specs). This means it will also look in subdirec-
tories for documents and classes that are in packages. However, any files located
outside the same directory structure will not be found using the default source path
compiler settings.
You can use the source-path option to specify one or more directories in which the
compiler should look for the MXML and ActionScript files. You can specify a list of
49. 22 | Chapter 2: Building Applications with the Flex Framework
directories by using spaces between directories. The following example looks for files
in the current directory as well as in C:FlexApplicationCommonLibraries:
mxmlc -source-path . C:FlexApplicationCommonLibraries -file-specs
SampleApplication.mxml
Customizing application background color
The default background color is the blue color you see for most Flex applications.
You can use the default-background-color option to customize the background
value. You can specify the value using 0x-prefixed hexadecimal representation in the
form of RRGGBB. The following sets the default background color of
SampleApplication to white:
mxmlc -default-background-color=0xFFFFFF SampleApplication.mxml
Note that the background color in this case is the background color of
Flash Player. Flex components including Application (the main con-
tainer of a Flex application) have backgrounds as well. Therefore, you
have to set the styles of a Flex application’s components in most cases.
Changing script execution settings
Flash Player automatically places restrictions on script execution in an attempt to pre-
vent applications from crashing client systems. This means that if too many levels of
recursion occur, or if a script takes too long to execute, Flash Player will halt the script.
The default-script-limits option allows you to customize each of these settings.
The option requires two values: one for the maximum level of recursion and one for
the maximum script execution time. The default maximum level of recursion is
1000, and the default maximum script execution time is 60 seconds (you cannot
specify a value larger than 60 for this parameter):
mxmlc -default-script-limits 200 15 -file-specs SampleApplication.mxml
While it’s important to know about the existence of default-script-
limits, it’s also important to know that it should rarely be used. If you
have to increase the default-script-limits setting for an application
to avoid an error, frequently it’s because there is a problem in the code
or in the application logic.
Setting metadata
The .swf format allows you to encode metadata in the application file. The allowable
metadata includes the following: title, description, creator, publisher, language,
and date. You can set these values using options with the same names as the meta-
data elements:
mxmlc -title "Sample Application" -description "A Flex Sample Application" -file-
specs SampleApplication.mxml
50. Building Applications | 23
Using incremental builds
By default, when you compile from the command line, mxmlc compiles a clean build
every time. That means that it recompiles every source file, even if it hasn’t changed
since you last compiled. That is because by default, mxmlc doesn’t have a way of
knowing what has changed and what hasn’t.
There are times when a clean build is exactly the behavior you want from mxmlc.
However, in most cases you’ll find that it’s faster to use incremental builds. An incre-
mental build is one in which the compiler recompiles only those elements that have
changed since you last compiled. For all other elements it uses the previously com-
piled versions. Assuming not much has changed since the previous compile, an incre-
mental build can be much faster than a clean build.
If you want to use incremental builds, you need a way to determine what things have
changed between builds. When you set the -incremental option to true, mxmlc writes
to a file in the same directory as the target file you are compiling, and it shares the
same name. The name of the cache file is TargetFile_#.cache, in which the # is a num-
ber generated by the compiler. For example, the following might write to a file called
SampleApplication_302345.cache (where the number is determined by the compiler):
mxmlc -incremental=true -file-specs SampleApplication.mxml
Storing compiler settings in configuration files
Although it is undoubtedly great fun to specify compiler options on the command
line, you can also store settings in configuration files. You can then specify the con-
figuration file as a single option from the command line. The load-config option lets
you specify the file you want to load to use as the configuration file:
mxmlc -load-config=configuration.xml SampleApplication.mxml
By default, mxmlc uses a configuration file called flex-config.xml located in the
frameworks directory of the SDK or Flex Builder installation. If you specify a value
for the load-config option, that can override the flex-config.xml. Many, though not
all, of the settings in flex-config.xml are required. That means that it’s important that
you do one of the following:
• Copy and modify the content of flex-config.xml for use in your custom configu-
ration file. When you do so, you will likely have to modify several values in the
file so that they point to absolute paths rather than relative paths. Specifically,
you have to modify:
— The <external-library-path> setting from the relative libs/playerglobal.swc
to a valid path pointing to the actual .swc file
— The <library-path> settings from libs and locale/{locale} to the valid
paths pointing to those resources (you can keep the {locale} variable)
51. 24 | Chapter 2: Building Applications with the Flex Framework
• Load your custom file in addition to the default. When you use the = operator to
assign a value to the load-config option you load the file in place of the default.
When you use the += operator, you load the file in addition to the default. Any
values specified in the custom configuration file override the same settings in the
default file:
mxmlc -load-config+=configuration.xml SampleApplication.mxml
Configuration files must have exactly one root node, and that root node must be a
<flex-config> tag. The <flex-config> tag should define a namespace as in the fol-
lowing example:
<flex-config xmlns="http://www.adobe.com/2006/flex-config">
</flex-config>
Within the root node you can nest nodes corresponding to compiler options. You
can configure any and every compiler option from a configuration file. However, the
option nodes must appear in the correct hierarchy. For example, some option nodes
must appear within a <compiler> tag, and others must appear within a <metadata>
tag. You can determine the correct hierarchy from the compiler help. The following
is a list of the options returned by mxmlc -help list:
-benchmark
-compiler.accessible
-compiler.actionscript-file-encoding <string>
-compiler.context-root <context-path>
-compiler.debug
-compiler.external-library-path [path-element] [...]
-compiler.fonts.max-glyphs-per-face <string>
-compiler.include-libraries [library] [...]
-compiler.incremental
-compiler.library-path [path-element] [...]
-compiler.locale <string>
-compiler.namespaces.namespace <uri> <manifest>
-compiler.optimize
-compiler.profile
-compiler.services <filename>
-compiler.show-actionscript-warnings
-compiler.show-binding-warnings
-compiler.show-deprecation-warnings
-compiler.source-path [path-element] [...]
-compiler.strict
-compiler.theme [filename] [...]
-compiler.use-resource-bundle-metadata
-file-specs [path-element] [...]
-help [keyword] [...]
-licenses.license <product> <serial-number>
-load-config <filename>
-metadata.contributor <name>
-metadata.creator <name>
-metadata.date <text>
-metadata.description <text>
-metadata.language <code>
52. Building Applications | 25
-metadata.localized-description <text> <lang>
-metadata.localized-title <title> <lang>
-metadata.publisher <name>
-metadata.title <text>
-output <filename>
-runtime-shared-libraries [url] [...]
-use-network
-version
-warnings
You’ll notice that some options you already know, such as incremental and title,
are prefixed (e.g., compiler.incremental and metadata.title). These prefixed com-
mands are the full commands. The compiler defines aliases that you can use from the
command line. That way, the compiler knows that when you type incremental, you
really mean compiler.incremental. However, when you use a configuration file, you
must use the full option names. Prefixes translate to parent nodes. For example, the
following sets the incremental option to true and the title option to Example:
<flex-config xmlns="http://www.adobe.com/2006/flex-config">
<compiler>
<incremental>true</incremental>
</compiler>
<metadata>
<title>Example</title>
</metadata>
</flex-config>
In the options list you’ll notice that some options are followed by a value enclosed in
<>. For example, the title option is followed by <text>. These values indicate that
the option value should be a string. For example, as you can see in the preceding
sample code, the <title> tag has a nested string value of Example. If an option is fol-
lowed by two or more <value> values, the option node should contain child tags with
the specified names. For example, the localized-title option is followed by <text>
<lang>. Therefore, the following is an example of a configuration file that correctly
describes the localized-title option:
<flex-config xmlns="http://www.adobe.com/2006/flex-config">
<metadata>
<localized-title>
<text>Example</text>
<lang>en_US</lang>
</localized-title>
</metadata>
</flex-config>
If an option is followed by [value] [...], it means the option node must contain one
or more tags with the name specified. For example, file-specs is followed by [path-
element] [...]. This means that the following is a valid configuration file specifying a
file-specs value:
<flex-config xmlns="http://www.adobe.com/2006/flex-config">
<file-specs>
53. 26 | Chapter 2: Building Applications with the Flex Framework
<path-element>Example.mxml</path-element>
</file-specs>
</flex-config>
The following is also a valid configuration file. This time it defines several target files
to compile:
<flex-config xmlns="http://www.adobe.com/2006/flex-config">
<file-specs>
<path-element>Example.mxml</path-element>
<path-element>Example2.mxml</path-element>
<path-element>Example3.mxml</path-element>
<path-element>Example4.mxml</path-element>
</file-specs>
</flex-config>
When an option is not followed by anything, it indicates that the value should be
Boolean. For example, incremental is not followed by anything in the list.
If you want a complete list of all compiler options you can use this command:
mxmlc -help advanced
Using Ant
Using the compiler from the command line is not the best way to build applications,
for the following reasons:
• It’s inconvenient because you have to open a command line and type the com-
mand each time.
• Because you have to type the command each time, there’s a greater chance of
introducing errors.
• Not only is opening a command line and typing a command inconvenient, but
it’s also slow.
• Compiling from the command line doesn’t allow you much in the way of fea-
tures, such as copying and deploying files, testing for dependencies, and so on.
A standard tool used by application developers for scripting application builds is a
program called Apache Ant. Ant (http://ant.apache.org) is an open source tool that
runs on Java to automate the build process. This includes testing for dependencies
(e.g., existence of directories), compiling, moving and copying files, and launching
applications. Although you can use .bat files or shell scripts to achieve many of Ant’s
basic tasks, Ant is extremely feature-rich (it offers support for compressing and
uncompressing archives, email support, and FTP support, to name just a few) and
can better handle potential errors than .bat or shell scripts.
If you’re not familiar with Ant, the first thing you should do is to download and
install Ant from http://ant.apache.org. Once you’ve installed Ant, you should add a
new environment variable, called ANT_HOME, as well as the Ant bin directory to the
54. Building Applications | 27
system path. The ANT_HOME environment variable should point to the root directory of
the Ant installation on the computer. For example, if Ant is installed at C:Ant on a
Windows system, the ANT_HOME environment variable should point to C:Ant. Addi-
tionally, you should add the Ant bin directory to the system path. For example, if
Ant is installed at C:Ant, add C:Antbin to the system path.
Ant uses XML files named build.xml. The build.xml file for a project contains all the
instructions that tell Ant how to compile and deploy all the necessary files (e.g., the
application). The build.xml file consists of a <project> root node that contains nested
target nodes. The project node allows you to define three attributes:
name
The name of the project
default
The name of the target to run when no other target is specified
basedir
The directory to use for all relative directory calculations
For our sample build.xml, the <project> node looks like this to start:
<project name="FlexTest" default="compile" basedir="./">
</project>
This says that the base directory is the directory in which the file is stored, and the
default target is called compile.
Within the <project> node is one or more <target> nodes. Each target node repre-
sents a named collection of tasks. Ant tasks could involve compiling an applica-
tion, moving files, creating directories, launching applications, creating ZIP
archives, using FTP commands, and so on. You can read all about the types of tasks
available within Ant at http://ant.apache.org/manual/tasksoverview.html. In our dis-
cussion of using Ant with Flex applications we’ll focus primarily on just a few of
the core Ant tasks, such as exec and move. The following defines the compile target
for our sample build.xml file:
<project name="FlexTest" default="compile" basedir="./">
<target name="compile">
<exec executable="C:FlexSDKbinmxmlc.exe">
<arg line="-file-specs FlexTest.mxml" />
</exec>
</target>
</project>
This compile target runs by default because it is set as the default for the project.
When you run the Ant build, the compile target runs the exec task with an execut-
able of C:FlexSDKbinmxmlc.exe (you’ll need to change the value to point to mxmlc.
exe on your system as necessary). Nested within the <exec> tag you can place one or
56. silence on the part of M. Xavier, this disdain for my person, irritated
me to the last degree. What should I have done, if that which I
expected had happened? I did not ask myself. I simply wanted it to
happen.
M. Xavier was really a very pretty boy, even prettier than his
photograph. A light blonde moustache—two little arcs of gold—set
off his lips better than in his portrait, their red and fleshy pulp
inviting a kiss. His light blue eyes, dusted with yellow, were strangely
fascinating, and his movements were characterized by the indolence,
the weary and cruel grace, of a girl or young deer. He was tall,
slender, very supple, ultra-modern in his elegance, and wonderfully
seductive through his evident cynicism and corruption. In addition to
the fact that he had pleased me from the first, his resistance, or,
rather, his indifference, caused my desire to quickly ripen into love.
One morning I found M. Xavier awake, and sitting on the edge of the
bed. I remember that he wore a white silk shirt with blue dots. I
modestly started to withdraw, but he called me back:
"Oh! what is the matter? Come in. You are not afraid of me, are
you?"
With his two hands clasped over his leg, and his body swaying to
and fro, he surveyed me for a long time with the utmost effrontery,
while I, with slow and graceful movements, and blushing a little,
placed a tray on the little table near the mantel. And, as if he then
really saw me for the first time, he said:
"Why, you are a very stylish girl. How long, then, have you been
here?"
"Three weeks, Monsieur."
"Well, that's astonishing!"
"What is astonishing, Monsieur?"
"That I have never noticed that you were so beautiful. Come here!"
said he.
57. I approached, trembling a little. Without a word he took me by the
waist, and forced me to sit down beside him.
"Oh! Monsieur Xavier," I sighed, struggling, but not very vigorously.
"Stop, I beg of you. If your parents were to see you?"
But he began to laugh:
"My parents! Oh! my parents, you know,—I have supped on them."
This was a phrase that he was continually using. When one asked
him anything, he answered: "I have supped on that." And he had
supped on everything.
To gain a little time I asked him:
"There is one thing that puzzles me, Monsieur Xavier. How does it
happen that one never sees you at Madame's dinners?"
"You certainly don't expect me, my dear ... oh! no, you know,
Madame's dinners tire me too much."
"And how is it," I insisted, "that your room is the only one in the
house in which there is not a picture of the pope?"
This observation flattered him. He answered:
"Why, my little baby, I am an Anarchist, I am. Religion, the Jesuits,
the priests,—oh! no, I have enough of them. I have supped on
them. A society made up of people like papa and mamma? Oh! you
know ... none of that in mine, thank you!"
Now I felt at ease with M. Xavier, in whom I found, together with the
same vices, the drawling accent of the Paris toughs. It seemed to
me that I had known him for years and years. In his turn he asked
me:
"Tell me, are you intimate with papa?"
"Your father!" I cried, pretending to be scandalized. "Oh! Monsieur
Xavier! Such a holy man!"
His laugh redoubled, and rang out loudly:
58. "Papa! Oh! papa! Why, he is intimate with all the servants here.
Then you are not yet intimate with papa? You astonish me."
"Oh! no," I replied, laughing also. "Only he brings me the 'Fin de
Siècle,' the 'Rigolo,' the 'Petites Femmes de Paris'."
That set him off in a delirium of joy, and, shaking more than ever
with laughter, he cried:
"Papa! Oh! he is astonishing!"
And, being now well started, he continued in a comical tone:
"He is like mamma. Yesterday she made me another scene. I am
disgracing her,—her and papa. Would you believe it? And religion,
and society, and everything! It is twisting. Then I declared to her:
'My dear little mother, it is agreed; I will settle down to a regular life
on the day when you shall have given up your lovers.' That was a
hot one, eh? That shut her up. Oh! no, you know, they make me
very tired, these authors of my being. I have supped on their
lectures. By the way, you know Fumeau, don't you?"
"No, Monsieur Xavier."
"Why, yes ... why, yes ... Anthime Fumeau?"
"I assure you that I do not."
"A fat fellow, very young, very red-faced, ultra-stylish, the finest
teams in Paris. Fumeau ... an income of three millions. Tartlet the
Kid? Why, yes, you know him."
"But I tell you that I do not know him."
"You astonish me! Why, everybody knows him. Don't you know the
Fumeau biscuit? The young fellow who had a judicial adviser
appointed for him two months ago? Don't you remember?"
"Not at all, I swear to you, Monsieur Xavier."
"Never mind, little turkey. Well, I played a good one on Fumeau last
year,—a very good one. Guess what? You do not guess?"
"How do you expect me to guess, since I do not know him?"
59. "Well, it was this, my little baby. I introduced Fumeau to my mother.
Upon my word! What do you think of that for a discovery? And the
funniest part of it is that in two months mamma succeeded in
blackmailing Fumeau to the tune of three hundred thousand bones.
What a godsend that, for papa's works! Oh! they know a thing or
two; they are up to snuff! But for that, the house would have gone
up. We were over head and ears in debt. The priests themselves
were refusing to have anything to do with us. What do you say to
that, eh?"
"I say, Monsieur Xavier, that you have a queer way of treating the
family."
"What do you expect, my dear? I am an Anarchist, I am. I have
supped on the family."
That morning Madame was even nicer than usual with me.
"I am well satisfied with your service," she said to me. "Mary, I raise
your wages ten francs."
"If she raises me ten francs every time," thought I to myself, "that
will not be bad. It is more suitable."
Oh! when I think of all that! I, too, have supped on it.
M. Xavier's fancy did not last long; he had quickly "supped on me."
Not for a moment, moreover, was I able to keep him in the house.
Several times, on entering his room in the morning, I found the bed
undisturbed and empty. M. Xavier had been out all night. The cook
knew him well, and she had told the truth when she said: "He
prefers to roam elsewhere." He pursued his old habits, and went in
search of his customary pleasures, as before. On those mornings I
felt a sudden pain in my heart, and all day long I was sad, sad!
The unfortunate part of it all is that M. Xavier had no feeling. He was
not poetical, like M. Georges. He did not vouchsafe me the slightest
60. attention. Never did he say to me a kind and touching word, as
lovers do in books and plays. Moreover, he liked nothing that I liked;
he did not like flowers, with the exception of the big carnations with
which he adorned the buttonhole of his coat. Yet it is so good to
whisper to each other things that caress the heart, to exchange
disinterested kisses, to gaze for eternities into one another's eyes.
But men are such coarse creatures; they do not feel these joys,—
these joys so pure and blue. And it is a great pity. M. Xavier knew
nothing but vice, found pleasure only in debauchery. In love all that
was not vice and debauchery bored him.
"Oh! no, you know, that makes me very tired. I have supped on
poetry. The little blue flower ... we must leave that to papa."
To him I was always an impersonal creature, the domestic to whom
he gave orders and whom he maltreated in the exercise of his
authority as master, and with his boyish cynical jests. And he often
said to me, with a laugh in the corner of his mouth,—a frightful
laugh that wounded and humiliated me:
"And papa? Really, you are not yet intimate with papa? You astonish
me."
Once I had not the power to keep back my tears; they were choking
me. M. Xavier became angry at once:
"Oh! no, you know, that is the most tiresome thing of all. Tears,
scenes? You must stop that, my dear; or else, good evening! I have
supped on all that nonsense."
For my part I feel an immense and imperative need of that pure
embrace, of that chaste kiss, which is no longer the savage bite of
the flesh, but the ideal caress of the soul. I need to rise from the hell
of love to the paradise of ecstasy, to the fullness, the delicious and
candid silence, of ecstasy. But M. Xavier had supped on ecstasy.
Nothing pained me so much as to see that I had not left the
slightest trace of affection, not the smallest tenderness, in his heart.
Yet I believe that I could have loved the little scoundrel,—that I
could have devoted myself to him, in spite of everything, like a
61. beast. Even to-day I think regretfully of his impudent, cruel, and
pretty phiz, and of his perfumed skin. And I have often on my lips,
from which, since then, so many lips ought to have effaced it, the
acid taste, the burning sensation of his kiss. Oh! Monsieur Xavier!
Monsieur Xavier!
One evening, before dinner, when he had returned to dress,—my!
but how nice he looked in evening dress!—and as I was carefully
arranging his affairs in the dressing-room, he asked me, without
embarrassment or hesitation, and almost in a tone of command,
precisely as he would have asked me for hot water:
"Have you five louis? I am in absolute need of five louis to-night. I
will return them to you to-morrow."
That very morning Madame had paid me my wages. Did he know it?
"I have only ninety francs," I answered, a little ashamed,—ashamed
of his question, perhaps, but more ashamed, I think, at not having
the entire sum that he asked.
"That makes no difference," said he; "go and get me the ninety
francs. I will return them to you to-morrow."
He took the money, and, by way of thanks, said in a dry, curt tone
that froze my heart: "That's good!" Then, putting out his foot with a
brutal movement, he commanded insolently:
"Tie my shoes. And be quick about it; I am in a hurry."
I looked at him sadly, imploringly:
"Then you are not to dine here this evening, Monsieur Xavier?"
"No, I dine in town. Make haste."
As I tied his shoes, I moaned:
62. "And you will not return to-night? I shall cry all night long. It is not
nice of you, Monsieur Xavier."
His voice became hard and thoroughly wicked.
"If you lent me your ninety francs that you might say that, you can
take them back. Here, take them!"
"No, no," I sighed. "You know very well that it was not for that."
"Well, then, don't bother me."
He had quickly finished dressing, and he started off without kissing
me and without saying a word.
The next day nothing was said about returning the money; and I did
not wish to claim it. It gave me pleasure to think that he had
something of me. And now I understand the women who kill
themselves with toil, the women who sell themselves to passers-by,
at night, on the sidewalks, the women who steal, and the women
who kill, in order to get a little money with which to procure
indulgences for the little man whom they love. That is what has
happened to me, in fact. Or has it really happened to me in the
degree that I say? Alas! I do not know. There are moments when, in
presence of a man, I feel so soft, so soft, without will, without
courage, so yielding ... yes, so yielding!
Madame was not slow in changing her manner toward me. Instead
of treating me nicely, as she had done before, she became severe,
exacting, fault-finding. I was only a blockhead; I never did anything
right; I was awkward, unclean, ill-bred, forgetful, dishonest. And her
voice, which at first had been so sweet, so much like the voice of a
comrade, now became as sour as vinegar. She gave me orders in a
blunt and humiliating tone. No more gifts of underwear, no more
cold cream and powder, no more of the secret counsels and private
confidences that had so embarrassed me at first. No more of that
63. suspicious comradeship which at bottom I felt not to be kindness,
and which caused me to lose my respect for this mistress who raised
me to the level of her own vice. I snapped at her sharply, strong in
my knowledge of all the open or hidden infamies of the house. We
got to quarreling like fish-wives, hurling our week's notice at each
other's heads, like dirty rags.
"What, then, do you take my house for?" she cried. "Do you think
you are working for a fast woman?"
Think of her cheek! I answered:
"Oh! your house is a clean one, indeed! You can boast of it. And
you? Let us talk about it; yes, let us talk about it! You are clean, too!
And what about Monsieur? Oh! la! la! And do you think they don't
know you in the neighborhood, and in Paris? Why, you are notorious,
everywhere. Your house? A brothel. And, in fact, there are brothels
which are not as dirty as your house."
And so these quarrels went on; we exchanged the worst insults and
the lowest threats; we descended to the vocabulary of the street-
walkers and the prisons. And then, suddenly, everything quieted
down. M. Xavier had only to show signs of a reviving interest in me,
—fleeting, alas!—when straightway began again the suspicious
familiarity, the shameful complicities, the gifts of garments, the
promises of doubled wages, the washing with Simon cream,—it is
more suitable,—and the initiations into the mysteries of refined
perfumes. M. Xavier's conduct toward me was the thermometer by
which Madame regulated her own. The latter's kindness immediately
followed the former's caresses. Abandonment by the son was
accompanied by insults from the mother. I was the victim,
continually tossed back and forth, of the enervating fluctuations to
which the intermittent love of this capricious and heartless boy was
subject. One would have thought that Madame must have played
the spy with us, must have listened at the door, must have kept tabs
for herself on the different phases of our relations. But no. She
simply had the instinct of vice, that's all. She scented it through
64. walls and souls, as a dog inhales in the breeze the far-away odor of
game.
As for Monsieur, he continued to dance about among all these
events, among all the hidden dramas of this house, alert, busy,
cynical, and comical. In the morning he disappeared, with his face of
a little pink and shaven faun, with his documents, with his bag
stuffed with pious pamphlets and obscene newspapers. In the
evening he reappeared, cravated with respectability, armored with
Christian Socialism, his gait a little slower, his gestures a little more
oily, his back slightly bent, doubtless under the weight of the good
works done during the day. Regularly every Friday he gave me the
week's issues of indecent journals, awaiting just the right occasion
for making his declaration, and contenting himself with smiling at me
with the air of an accomplice, caressing my chin, and saying to me,
as he passed his tongue over his lips:
"Ho, ho, she is a very queer little one, indeed!"
As it amused me to watch Monsieur's game, I did not discourage
him, but I promised myself to seize the first exceptionally favorable
opportunity to sharply put him where he belonged.
One afternoon I was greatly surprised to see him enter the linen-
room, where I sat alone, musing sadly over my work. In the morning
I had had a painful scene with M. Xavier, and was still under the
influence of the impression it had left on me. Monsieur closed the
door softly, placed his bag on the large table near a pile of cloth,
and, coming to me, took my hands and patted them. Under his
blinking eyelid his eye turned, like that of an old hen dazzled by the
sunlight. It was enough to make one die of laughter.
"Célestine," said he, "for my part, I prefer to call you Célestine. That
does not offend you, does it?"
I could hardly keep from bursting.
65. "Why, no, Monsieur," I answered, holding myself on the defensive.
"Well, Célestine, I think you charming! There!"
"Really, Monsieur?"
"Adorable, in fact; adorable, adorable!"
"Oh! Monsieur!"
His fingers had left my hand, and were caressing my neck and chin
with fat and soft little touches.
"Adorable, adorable!" he whispered.
He tried to embrace me. I drew back a little, to avoid his kiss.
"Stay, Célestine, I beg of you. I do not annoy you, do I?"
"No, Monsieur; you astonish me."
"I astonish you, you little rogue. I astonish you? Oh! you don't know
me."
His voice was no longer dry. A fine froth moistened his lips.
"Listen to me, Célestine. Next week I am going to Lourdes; yes, I
conduct a pilgrimage to Lourdes. Do you wish to come to Lourdes? I
have a way of taking you to Lourdes. Will you come? Nobody will
notice anything. You will stay at the hotel; you will take walks, or do
what you like. And I will meet you in the evening."
What stupefied me was not the proposition in itself,—for I had been
expecting it a long time,—but the unforeseen form which Monsieur
gave it. Yet I preserved all my self-possession. And, desirous of
humiliating this old rake, of showing him that I had not been the
dupe of Madame's dirty calculations and his own, I lashed him
squarely in the face with these words:
"And M. Xavier? Say, it seems to me that you are forgetting M.
Xavier? What is he to do while we are amusing ourselves in Lourdes,
at the expense of Christianity?"
66. An indirect and troubled gleam, the look of a surprised deer, lighted
in the darkness of his eyes. He stammered:
"M. Xavier?"
"Why, yes!"
"Why do you speak to me of M. Xavier? There is no question of M.
Xavier? M. Xavier has nothing to do with this."
I redoubled my insolence.
"On your word? Oh! don't pretend to be ignorant. Am I hired, yes or
no, to be company for M. Xavier? Yes, am I not? Well, I am company
for him. But you? Oh! no, that is not in the bargain. And then, you
know, my little father, you are not my style."
And I burst out laughing in his face.
He turned purple; his eyes flamed with anger. But he did not think it
prudent to enter into a discussion, for which I was terribly armed.
He hastily picked up his bag, and slunk away, pursued by my
laughter.
The next day, apropos of nothing, Monsieur made some gross
remark to me. I flew into a passion. Madame happened along. I
became mad with anger. The scene that ensued between us three
was so frightful, so low, that I cannot undertake to describe it. In
unspeakable terms I reproached them with all their filth and with all
their infamy. I demanded the return of the money that I had lent M.
Xavier. They foamed at the mouth. I seized a cushion, and hurled it
violently at Monsieur's head.
"Go away! Get out of here, at once, at once!" screamed Madame,
threatening to tear my face with her nails.
"I erase your name from the membership of my society; you no
longer belong to my society, lost creature, prostitute!" vociferated
Monsieur, stuffing his bag with thrusts of his fists.
Finally Madame withheld my week's wages, refused to pay the
ninety francs that I had lent M. Xavier, and obliged me to return all
67. the rags that she had given me.
"You are all thieves," I cried; "you are all pimps!"
And I went away, threatening them with the commissary of police
and the justice of the peace.
"Oh! you are looking for trouble? Yes, well, you shall have it,
scoundrels that you are!"
Alas! the commissary of police pretended that the affair did not
concern him. The justice of the peace advised me to let it drop. He
explained:
"In the first place, Mademoiselle, you will not be believed. And that
is as it should be. What would become of society if a servant could
be right against a master? There would be no more society,
Mademoiselle. That would be anarchy."
I consulted a lawyer; he demanded two hundred francs. I wrote to
M. Xavier; he did not answer me. Then I counted up my resources. I
had three francs fifty left—and the street pavement.
XIII
November 13.
And I see myself again at Neuilly, with the sisters of Our Lady of
Thirty-Six Sorrows, a sort of house of refuge, and also an
employment-bureau for housemaids. My! but it is a fine
establishment, with a white front, and at the rear of a large garden.
In the garden, which is ornamented, at intervals of fifty steps, with
statues of the Virgin, there is a little chapel, very new and
sumptuous, built from the proceeds of the collections. Large trees
surround it. And every hour one hears the tolling of the bells. It is so
nice to hear the bells toll. It stirs in one's heart memories of things
so old and long forgotten. When the bells toll, I close my eyes and
68. listen, and I see again landscapes which perhaps I never saw before,
and which I recognize all the same,—very peaceful landscapes,
imbued with all the transformed recollections of childhood and
youth,... and bagpipes,... and, on the moor bordering on the
beaches, the slowly-moving panorama of holiday crowds. Ding ...
dinn ... dong! It is not very gay; it is not the same thing as gaiety; it
is even sad at bottom,—sad, like love. But I like it. In Paris one
never hears anything but the fountaineer's horn, and the deafening
trumpet of the tramway.
In the establishment of the sisters of Our Lady of Thirty-Six Sorrows,
you sleep in attic dormitories; you are fed meagrely on scraps of
meat and spoiled vegetables, and you pay twenty-five sous a day to
the institution. That is to say, the sisters withhold twenty-five sous
from your wages, when they have secured a place for you. They call
that getting you a place for nothing. Further, you have to work from
six o'clock in the morning until nine in the evening, like the inmates
of prisons. You are not allowed to go out. Meals and religious
exercises take the place of recreation. Ah! the good sisters do not
bore themselves, as M. Xavier would say; and their charity is a
famous trap. They rope you in finely! But there it is,—I shall be
stupid all my life. The stern lessons of experience, the succession of
misfortunes, never teach me anything, are of no use to me. I am
always crying out and raising a row, but in the end I am always
victimized by everybody.
Several times comrades had spoken to me of the sisters of Our Lady
of Thirty-Six Sorrows.
"Yes, my dear, it seems that only very swell people come to the
box,... countesses,... marchionesses. One may chance on
astonishing places."
I believed it. And then, in my distress, I remembered with some
feeling, booby that I am, the happy years that I spent with the little
sisters of Pont-Croix. Moreover, I had to go somewhere. Beggars
cannot be choosers.
69. When I arrived, there were forty housemaids there. Many came from
a great distance,—from Brittany, from Alsace, from the south, girls
who had never yet had a place,—awkward, clumsy, with livid
complexions, sly airs, and singular eyes that looked over the walls of
the convent at the mirage of Paris lying beyond. Others, not as
green, were just out of a place, like myself.
The sisters asked me whence I came, what I knew how to do,
whether I had good references, and whether I had any money left. I
told them all sorts of things, and without further inquiry they
welcomed me, saying:
"This dear child! We will find her a good place."
We all were their "dear children." While waiting for the promised
good place, each of these dear children was put at some work,
according to her faculties. Some did cooking and housework; others
worked in the garden, digging in the soil, like navvies. I was
promptly put at sewing, having, said Sister Boniface, supple fingers
and a distinguished air. I began by mending the chaplain's
pantaloons and the drawers of a sort of monk who was just then
preaching a retreat in the chapel. Oh! those pantaloons! Oh! those
drawers! Surely they did not resemble M. Xavier's. Then they
intrusted to me tasks less ecclesiastical,—quite profane, in fact,—the
making of fine and delicate linen garments, among which I again
found myself in my element. I participated in the making of elegant
bridal trousseaux, of rich baby-linen, ordered of the good sisters by
charitable and wealthy ladies who were interested in the
establishment.
At first, after so many shocks, in spite of the bad food, the chaplain's
pantaloons, the lack of liberty, in spite of all the fierce exploitation
that I could plainly see, I felt a sense of real relief amid this calm
and silence. I did not reason much; I felt rather a need of prayer.
Remorse over my past conduct, or, rather, the weariness resulting
from it, prompted me to fervent repentance. Several times in
succession I confessed to the chaplain. He was a queer man, this
chaplain, very round and red, a little rude in manner and in speech,
70. and afflicted with a disagreeable body-smell. He asked me strange
questions, and insisted on knowing my favorite authors.
"Armand Silvestre? Yes. To be sure, he is dirty. I would not give you
his works instead of the 'Imitation.' No, not that; yet he is not
dangerous. But you must not read impious books, books against
religion,—Voltaire, for instance. No, never; never read Voltaire,—that
is a mortal sin,—or Renan, or Anatole France. They are dangerous."
"And Paul Bourget, Father?"
"Paul Bourget! He is entering on the right path; that I do not deny.
But his Catholicism is not sincere,—not yet; at least, it is much
mixed. Your Paul Bourget makes upon me the impression of a wash-
basin,—yes, that is it,—of a wash-basin, in which no matter what
has been washed, and in which olives from Calvary are swimming
amid hair and soapsuds. You should wait a little before reading him!
Huysmans! Well, he is a little stiff in his expressions,—yes, indeed,
very stiff,—but he is orthodox."
And he said to me further:
"Yes ... Ah! you do mad things with your body! That is not good. No,
indeed, that is always bad. But, sin for sin, it is better to sin with
your masters, when they are pious persons, than with people of your
own condition. It is less serious, less irritating to the good God. And
perhaps these people have dispensations. Many have dispensations."
As I named M. Xavier and his father, he cried:
"No names. I do not ask you for names. Never tell me names. I do
not belong to the police. Besides, those are rich and respectable
people whom you have just named,—extremely religious people.
Consequently you are wrong; you are rebellious against morality and
against society."
These ridiculous conversations considerably cooled my religious zeal,
my ardor for repentance. The work, too, annoyed me. It made me
homesick for my own calling. I felt impatient desires to escape from
this prison, to return to the privacies of dressing-rooms. I sighed for
71. the closets full of sweet-smelling linen, the wardrobes stuffed with
silks, satins, and velvets, so smooth to the touch, and the bath-
rooms where white flesh is lathered with oily soaps. And the stories
of the servants' hall, and the unforeseen adventures, and the
evenings on the stairs and in the chambers! It is really curious;
when I have a place, these things disgust me, but, when I am out of
a place, I miss them. I was tired also, excessively tired, sickened in
fact, from having eaten for a week nothing but preserves made out
of spoiled currants, of which the good sisters had purchased a large
quantity in the Levallois market. Anything that the holy women could
rescue from the refuse-heap was good enough for us.
What completed my irritation was the evident, the persistent
effrontery with which we were exploited. Their game was a very
simple one, and they took little pains to conceal it. They found
places only for those girls of whom they could make no use
themselves. Those from whom they could reap any profit whatever
they held as prisoners, taking advantage of their talents, of their
strength, and of their simplicity. As the height of Christian charity,
they had found a way of having servants who paid for the privilege
of working, and whom they stripped, without remorse and with
inconceivable cynicism, of their modest resources and their little
savings, after making a profit out of their labor. And the costs kept
running on.
I complained, at first feebly, and then more forcibly, that they had
not once summoned me into the reception-room, but to all my
complaints the hypocrites answered:
"A little patience, my dear child! We are planning to get you an
excellent place, my dear child; for you we desire an exceptional
place. We know what sort of a place you should have. As yet not
one has offered itself such as we wish for you, and such as you
deserve."
Days and weeks passed. The places were never good enough, never
exceptional enough for me. And the costs kept running on.
72. Although there was a watcher in the dormitory, the things that went
on every night were enough to make one shudder. As soon as the
watcher had finished her round, and every one seemed to be asleep,
you could see white forms arise and glide about among the beds.
The good sisters, holy women, closed their eyes that they might see
nothing, stopped up their ears that they might hear nothing. Wishing
to avoid scandal, they tolerated horrors of which they feigned
ignorance. And the costs kept running on.
Fortunately, when I was at the very depth of my ennui, I was
delighted by the entrance into the establishment of a little friend,
Clémence, whom I called Cléclé, and whom I had known in a place
where I had worked in the Rue de l'Université. Cléclé was a
charming pink blonde, extremely gay and lively, and very fly. She
laughed at everything, accepted everything, and was contented
everywhere. Devoted and faithful, she knew but one pleasure,—that
of being useful to others. Vicious to the marrow of her bones, her
vice had nothing repugnant about it, it was so gay, artless, and
natural. She bore vice as a plant bears flowers, as a cherry-tree
bears cherries. Her pretty, bird-like chatter sometimes made me
forget my feeling of weariness, and put to sleep my tendency to
rebel. Our two beds were next to each other; and one night she told
me, in a funny sort of whisper, that she had just had a place in the
house of a magistrate at Versailles.
"Fancy, there were nothing but animals in the den,—cats, three
parrots, a monkey, and two dogs. And they all had to be taken care
of. Nothing was good enough for them. We were fed on old scraps,
the same as in this box here. But they had what was left over of the
poultry; they had cream, and cakes, and mineral water, my dear!
Yes, the dirty beasts drank nothing but Evian water, because of an
epidemic of typhoid fever that was raging at Versailles. In the winter
Madame had the cheek to take the stove out of my chamber, and
put it in the room where the monkey and the cats slept. Would you
believe it? I detested them, especially one of the dogs, a horrible old
pug, that was always sniffing at my skirts, in spite of the kicks that I
73. gave it. The other morning Madame caught me whipping it. You can
imagine the scene. She showed me the door in double-quick time."
Oh! this Cléclé! how agreeable and amusing she was!
People have no idea of all the annoyances to which domestics are
subjected, or of the fierce and eternal exploitation under which they
suffer. Now the masters, now the keepers of employment-bureaus,
now the charitable institutions, to say nothing of the comrades,
some of whom are capable of terrible meanness. And nobody takes
any interest in anybody else. Each one lives, grows fat, and is
entertained by the misery of some one poorer than himself. Scenes
change, settings are shifted, you traverse social surroundings that
are different and even hostile, but everywhere you find the same
appetites and passions. In the cramped apartments of the bourgeois
and in the elegant mansion of the banker you meet the same filth,
and come in contact with the inexorable. The result of it all, for a girl
like me, is that she is conquered in advance, wherever she may go
and whatever she may do. The poor are the human manure in which
grow the harvests of life, the harvests of joy which the rich reap,
and which they misuse so cruelly against us. They pretend that there
is no more slavery. Oh! what nonsense? And what are domestics,
then, if not slaves? Slaves in fact, with all that slavery involves of
moral vileness, inevitable corruption, and hate-engendering
rebellion. Servants learn vice in the houses of their masters. Entering
upon their duties pure and innocent,—some of them,—they are
quickly made rotten by contact with habits of depravity. They see
nothing but vice, they breathe nothing but vice, they touch nothing
but vice. Consequently, from day to day, from minute to minute,
they get more and more used to it, being defenceless against it,
being obliged, on the contrary, to serve it, to care for it, to respect it.
And their revolt arises from the fact that they are powerless to
satisfy it, and to break down all the obstacles in the way of its
natural expansion. Oh! it is extraordinary. They demand of us all the
74. virtues, complete resignation, all the sacrifices, all the heroisms, and
only those vices that flatter the vanity of the masters, and which
yield them a profit. And all this in return for contempt and wages
ranging from thirty-five to ninety francs a month. No, it is too much!
Add that we live in perpetual distress of mind, in a perpetual
struggle between the ephemeral semi-luxury of the places that we
fill, and the anguish which the loss of these places causes us. Add
that we are continually conscious of the wounding suspicions that
follow us everywhere,—bolting doors, padlocking drawers, marking
bottles, numbering cakes and prunes, and continually putting us to
shame by invasive examination of our hands, our pockets, and our
trunks. For there is not a door, not a closet, not a drawer, not a
bottle, not an article, that does not cry out to us: "Thief! thief!
thief!" And also the continuous vexation caused by that terrible
inequality, that frightful disproportion in our destinies, which, in spite
of familiarities, smiles, and presents, places between our mistresses
and ourselves an impassable abyss, a whole world of sullen hatreds,
suppressed desires, and future vengeances,—a disproportion which
is rendered every minute more perceptible, more humiliating, more
disgracing, by the caprices, and even by the kindnesses, of those
beings that know no justice and feel no love,—the rich. Did you ever
think for a moment of the mortal and legitimate hatred, of the
murderous—yes, murderous—desires with which we must be filled
when we hear one of our masters, in trying to describe something
base and ignoble, cry out in our presence, with a disgust that casts
us so violently outside the pale of humanity: "He has the soul of a
domestic; that is the sentiment of a domestic." Then what do you
expect us to become in these hells? Do these mistresses really
imagine that I should not like to wear fine dresses, ride in fine
carriages, have a gay time with lovers, and have servants of my
own? They talk to us of devotion, of honesty, of fidelity. Why; but it
would choke you to death, my little chippies!
75. Once, in the Rue Cambon ... how many of these places I have
had!... the masters were marrying their daughter. They gave a grand
reception in the evening, at which the wedding-presents were
exhibited,—enough of them to fill a furniture-van. By way of jest I
asked Baptiste, the valet de chambre:
"Well, Baptiste, and you? What is your present?"
"My present?" exclaimed Baptiste, with a shrug of his shoulders.
"Yes, tell me, what is it?"
"A can of petroleum lighted under their bed. That is my present."
It was a smart answer. Moreover, this Baptiste was an astonishing
man in politics.
"And yours, Célestine?" he asked, in his turn.
"Mine?"
I contracted my two hands into the shape of talons, and, pretending
to claw a face ferociously, I answered:
"My nails, in their eyes!"
The butler, without being asked, remarked quietly, while arranging
flowers and fruits in a glass dish with his fastidious fingers:
"I would be satisfied to sprinkle their faces in church with a bottle of
good vitriol."
And he stuck a rose between two pears.
Oh! yes, how we love them! The extraordinary thing is that these
revenges are not taken more frequently. When I think that a cook,
for instance, holds her masters' lives in her hands every day; a pinch
of arsenic instead of salt, a little dash of strychnine instead of
vinegar, and the thing is done. Well, no, it must be that we have
servitude in our very blood!
I have no education, and I write what I think and what I have seen.
Well, I say that all this is not beautiful. I say that from the moment
when any one installs another under his roof, though he were the
76. last of poor devils, or the lowest of disreputable girls, he owes them
protection, he owes them happiness. I say also that, if the master
does not give it to us, we have a right to take it, even from his
strong-box, even from his blood.
But enough of this! I do wrong to think of things that make my head
ache and turn my stomach. I come back to my little stories.
I had much difficulty in leaving the sisters of Our Lady of Thirty-Six
Sorrows. In spite of Cléclé's companionship, I was growing old in the
box, and beginning to be hungry for liberty. When they understood
that I had made up my mind to go, then the worthy sisters offered
me places and places. There were places only for me. But I am not
always a fool, and I have a keen eye for rascalities. All these places I
refused. In all of them I found something that did not suit me. You
should have seen the heads of these holy women. It was laughable.
They had calculated on finding me a place in the house of some old
bigot, where they could get back out of my wages the cost of my
board with usury, and I enjoyed playing them a trick in my turn.
One day I notified Sister Boniface that it was my intention to go that
very evening. She had the cheek to answer me, raising her arms to
heaven:
"But, my dear child, it is impossible."
"How so? Why is it impossible?"
"Why, my dear child, you cannot leave the house like that. You owe
us more than seventy francs. You will have to pay us first these
seventy francs."
"And with what?" I replied. "I have not a sou; you can search me."
Sister Boniface gave me a hateful look, and, then declared, with
severe dignity: "But, Mademoiselle, do you know that this is a
77. robbery? And to rob poor women like us is worse than robbery; it is
a sacrilege, for which the good God will punish you. Reflect."
Then anger got the better of me, and I cried:
"Say, then, who is it that steals here,—you or I? No, but you are
astonishing, my little mothers."
"Mademoiselle, I forbid you to speak in this way."
"Oh! don't talk to me. What? One does your work, one toils like a
beast for you from morning to night, one earns enormous money for
you, you give us food which dogs would refuse, and then we must
pay you into the bargain! Indeed, you have no cheek!"
Sister Boniface had turned very pale. I felt that coarse, filthy, furious
words were on her lips, and ready to leave them; but, not daring to
let them go, she stammered:
"Silence! You are a girl without shame, without religion. God will
punish you. Go, if you will; but we keep your trunk."
I planted myself squarely before her, in an attitude of defiance, and,
looking her full in the face, I said:
"Well, I should like to see you try it. Just try to keep my trunk, and
you will have a visit from the commissary of police in short order.
And, if religion consists in patching the dirty pantaloons of your
chaplains, in stealing bread from poor girls, in speculating on the
horrors that go on every night in the dormitory...."
The good sister was fairly white. She tried to cover my voice with
her own.
"Mademoiselle, Mademoiselle!"
"Oh! don't pretend ignorance of the dirty things that go on every
night in the dormitory! Do you dare to tell me, in my face, your eyes
looking into mine, that you are ignorant of them? You encourage
them because they are profitable to you,—yes, because they are
profitable to you."
78. And trembling, panting, with dry throat, I completed my accusation.
"If religion is all that; if it is religious to keep a prison and a brothel,
—well, then, I have enough of religion. My trunk, do you hear? I
wish my trunk. You will give me my trunk at once."
Sister Boniface was frightened.
"I do not wish to discuss with a lost creature," said she, in a voice of
dignity. "All right; you shall go."
"With my trunk?"
"With your trunk."
"Very well; but it takes tall talk to get one's rights here. It is worse
than at the custom-house."
I went, in fact, that very evening. Cléclé, who was very nice, and
who had saved something, lent me twenty francs. I went to engage
a room in a lodging-house in the Rue de la Sourdière, and I bought
a seat among the gallery-gods at the Porte-Saint-Martin. The play
was "The Two Orphans." How true it is! Almost my own story.
I passed there a delightful evening, weeping, weeping, weeping.
XIV
November 18.
Rose is dead. Decidedly, misfortune hangs over the captain's house.
Poor captain! His ferret dead ... Bourbaki dead ... and now it is
Rose's turn! After a sickness of some days, she was carried off day
before yesterday, in the evening, by a sudden attack of congestion
of the lungs. She was buried this morning. From the windows of the
linen-room I saw the procession pass in the road. The heavy coffin,
borne by six men, was covered with crowns and with bunches of
white flowers, like that of a young virgin. A considerable crowd, in
79. long, dark, babbling files,—all Mesnil-Roy—followed Captain Mauger,
who, wearing a tightly-fitting black frock-coat, and holding himself
very stiffly, led the mourners, in thoroughly military fashion. And the
church bells, tolling in the distance, responded to the sound of the
rattle waved by the beadle. Madame had warned me that I was not
to go to the funeral. However, I had no desire to go. I did not like
this fat and wicked woman; her death leaves me very calm and
indifferent. Yet perhaps I shall miss Rose; perhaps I shall miss my
occasional conversations with her in the road. But what a source of
gossip this event must be at the grocer's!
I was curious to know what impression this sudden death had made
upon the captain. And, as my masters were visiting, I took a walk in
the afternoon along the hedge. The captain's garden is sad and
deserted. A spade stuck in the ground indicates abandoned work.
"The captain will not come into the garden," said I to myself; "he is
undoubtedly weeping in his chamber, among the souvenirs." And
suddenly I perceive him. He has taken off his fine frock-coat, and
put on his working-clothes again, and, with his old foraging-cap on
his head, he is engaged in manuring his lawns. I even hear him
humming a march in a low voice. He leaves his wheelbarrow, and
comes toward me, carrying his fork on his shoulder.
"I am glad to see you, Mademoiselle Célestine."
I should like to offer him consolation or pity. I search for words, for
phrases. But how can one find a touching word in presence of such
a droll face? I content myself with repeating:
"A great misfortune, captain, a great misfortune for you! Poor Rose!"
"Yes, yes," he says, tamely.
His face is devoid of expression. His movements are uncertain. He
adds, jabbing his fork into a soft spot in the ground near the hedge:
"Especially as I cannot get along without anybody."
I insist upon Rose's domestic virtues.
"You will not easily replace her, Captain."
80. Decidedly, he is not touched at all. One would say even, from
looking at his eyes that have suddenly become brighter and from
watching his movements, now more alert, that he has been relieved
from a great weight.
"Bah!" says he, after a short silence, "everything can be replaced."
This resignation astonishes me, and even scandalizes me a little. To
amuse myself, I try to make him understand all he has lost in losing
Rose.
"She knew so well your habits, your tastes, your manias! She was so
devoted to you!"
"Well, if she had not been, that would have been the last straw," he
growled.
And, making a gesture by which he seems to put aside all sorts of
objections, he goes on:
"Besides, was she so devoted to me? Oh! I may as well tell you the
truth. I had had enough of Rose. Yes, indeed! After we took a little
boy to help us, she attended to nothing in the house, and everything
went badly, very badly. I could not even have an egg boiled to my
taste. And the scenes that went on, from morning to night, apropos
of nothing. If I spent ten sous, there were cries and reproaches.
And, when I talked with you, as I am doing now,—well, there was a
row, indeed; for she was jealous, jealous. Oh! no. She went for you;
you should have heard her. In short, I was no longer at home in my
own house."
He breathes deeply, noisily, and, with the new and deep joy that a
traveler feels on returning from a long journey, he contemplates the
sky, the bare grass-plots in the garden, the violet interlacings of the
branches of the trees against the light, and his little house.
This joy, so offensive to Rose's memory, now seems to me very
comical. I stimulate the captain to further confidences. And I say to
him, in a tone of reproach:
"Captain, I think you are not just to Rose."
81. "Egad!" he rejoins, quickly. "You do not know; you don't know
anything about it. She did not go to tell you of all the scenes that
she made, her tyranny, her jealousy, her egoism. Nothing belonged
to me here any longer. Everything in my house was hers. For
instance, you would not believe it, my Voltaire arm-chair was never
at my disposition. She had it all the time. She had everything, for
that matter. To think that I could no longer eat asparagus with oil,
because she did not like it! Oh! she did well to die. It was the best
thing that could happen to her, for, in some way or other, I should
have gotten rid of her. Yes, yes, I should have gotten rid of her. She
was becoming too much for me. I had had enough. And let me tell
you; if I had died before her, Rose would have been prettily trapped.
I had a bitter pill in store for her. My word for it!"
His lip curls in a smile that ends in an atrocious grimace. He
continues, chopping each of his words with moist little puffs of
laughter:
"You know that I made a will, in which I gave her everything,—
house, money, dividends, everything. She must have told you; she
told everybody. Yes, but what she did not tell you, because she did
not know it, is that, two months later, I made a second will,
cancelling the first, in which I did not leave her anything,—not a
sou."
Unable to contain himself longer, he bursts out laughing, a strident
laugh that scatters through the garden like a flight of scolding
sparrows. And he cries:
"Ah! that's an idea, hey? Oh! her head,—you can see it from here,—
on learning that I had left my little fortune to the French Academy.
For, my little Célestine, it is true; I had left my fortune to the French
Academy. Ah! that's an idea!"
I allow his laughter to become quieter, and then I gravely ask him:
"And now, Captain, what are you going to do?"
The captain gives me a long, sly, amorous look, and says:
82. "Well, that depends on you."
"On me?"
"Yes, on you; on you alone."
"And how is that?"
A moment of silence follows, during which, straightening up and
twisting his pointed beard, he seeks to envelop me in a seductive
fluid.
"Come," he says, suddenly, "let us go straight to the point. Let us
speak squarely,—soldier-fashion. Do you wish to take Rose's place?"
I was expecting the attack. I had seen it coming from the depth of
his eyes. It does not surprise me. I receive it with a serious and
unmoved expression.
"And the wills, Captain?"
"Oh! I tear them up."
I object:
"But I do not know how to cook."
"Oh! I will do the cooking; I will make my bed; I will do everything."
He becomes gallant, sprightly; his eye sparkles. He leans towards
the hedge, stretching out his neck. His eyes become bloodshot. And
in a lower voice he says:
"If you came to me, Célestine,—well...."
"Well, what?"
"Well, the Lanlaires would die of rage. Ah! that's an idea!"
I lapse into silence, and pretend to be profoundly dreaming. The
captain becomes impatient. He digs the heels of his shoes into the
sandy path.
"See, Célestine, thirty-five francs a month; the master's table; the
master's room; a will; does that suit you? Answer me."
83. "We will see later. But, while waiting, take another."
And I run away that I may not blow into his face the tempest of
laughter that is roaring in my throat.
I have, then, only the embarrassment of choice. The captain or
Joseph? To live as a servant-mistress, with all the contingencies that
such a position involves,—that is, to remain still at the mercy of a
stupid, coarse, changeable man, and dependent upon a thousand
disagreeable circumstances and a thousand prejudices; or else to
marry, and thus acquire a sort of regular and respected liberty, in a
situation free from the control of others, and liberated from the
caprice of events? Here at last a portion of my dream promises to be
realized.
It is very evident that I should have liked a realization on a grander
scale. But, when I think how few chances present themselves, in
general, in the existence of a woman like me, I must congratulate
myself that something is coming to me at last other than this eternal
and monotonous tossing back and forth from one house to another,
from one bed to another, from one face to another face.
Of course, I put aside at once the captain's plan. Moreover, I had no
need of this last conversation with him to know the sort of grotesque
and sinister mountebank, the type of odd humanity, that he
represents. Beyond the fact that his physical ugliness is complete,—
for there is nothing to relieve and correct it,—he gives one no hold
on his soul. Rose believed firmly in her assured domination over this
man, and this man tricked her. One cannot dominate nothing; one
can have no influence over emptiness. I cannot, without choking
with laughter, think of myself for an instant in the arms of this
ridiculous personage and caressing him. Yet, in spite of this, I am
content, and I feel something akin to pride. However low the source
from which it comes, it is none the less an homage, and this homage
strengthens my confidence in myself and in my beauty.
84. Quite different are my feelings toward Joseph. Joseph has taken
possession of my mind. He retains it, he holds it captive, he
obsesses it. He disturbs me, bewitches me, and frightens me, by
turns. Certainly, he is ugly, brutally, horribly ugly; but, when you
analyze this ugliness, you find something formidable in it, something
that is almost beauty, that is more than beauty, that is above beauty,
—something elemental. I do not conceal from myself the difficulty,
the danger, of living, whether married or not, with such a man, of
whom I am warranted in suspecting everything, and of whom, in
reality, I know nothing. And it is this that draws me to him with a
dizzy violence. At least he is capable of many things in crime,
perhaps, and perhaps also in the direction of good. I do not know.
What does he want of me? What will he do with me? Should I be the
unscrupulous instrument of plans that I knew nothing of, the
plaything of his ferocious passions? Does he even love me? And why
does he love me? For my beauty; for my vices; for my intelligence;
for my hatred of prejudices,—he who makes parade of all the
prejudices? I do not know. In addition to this attraction which the
unknown and mysterious has for me, he exercises over me the
bitter, powerful charm of force. And this charm, yes, this charm acts
more and more on my nerves, conquers my passive and submissive
flesh. It is something which I cannot define exactly, something that
takes me wholly, by my mind and by my sex, revealing in me
instincts of which I was unaware, instincts that slept within me
without my knowledge, and that no love, no thrill of voluptuousness
had before awakened. And I tremble from head to foot when I
remember the words of Joseph, saying to me:
"You are like me, Célestine. Oh! not in features, of course. But our
two souls are alike; our two souls resemble each other."
Our two souls! Is that possible?
These sensations that I feel are so new, so imperious, so strongly
tenacious, that they do not leave me a minute's rest, and that I
remain always under the influence of their stupefying fascination. In
vain do I seek to occupy my mind with other thoughts. I try to read
85. and walk in the garden, when my masters are away, and, when they
are at home, to work furiously at my mending in the linen-room.
Impossible! Joseph has complete possession of my thought. And not
only does he possess it in the present, but he possesses it also in
the past. Joseph so interposes himself between my entire past and
myself that I see, so to speak, nothing but him, and that this past,
with all its ugly or charming faces, draws farther and farther from
me, fades away, disappears. Cléophas Biscouille; M. Jean; M. Xavier;
William, of whom I have not yet spoken; M. Georges, himself, by
whom I believed my soul to have been branded forever, as the
shoulder of the convict is branded by the red iron; and all those to
whom, voluntarily, joyously, passionately, I have given a little or
much of myself, of my vibrant flesh and of my sorrowful heart,—all
of them shadows already! Uncertain and ludicrous shadows that
fade away until they are hardly recollections, and then become
confused dreams ... intangible, forgotten realities ... vapors ...
nothing. Sometimes, in the kitchen, after dinner, when looking at
Joseph and his criminal mouth, and his criminal eyes, and his heavy
cheek-bones, and his low, knotty, humpy forehead, upon which the
lamplight accumulates hard shadows, I say to myself:
"No, no, it is not possible. I am under the influence of a fit of
madness; I will not, I cannot, love this man. No, no, it is not
possible."
And yet it is possible, and it is true. And I must at last confess it to
myself, cry out to myself: "I love Joseph!"
Ah! now I understand why one should never make sport of love;
why there are women who rush, with all the consciencelessness of
murder, with all the invincible force of nature, to the kisses of brutes
and to the embraces of monsters, and who voluptuously sound the
death-rattle in the sneering faces of demons and bucks.
86. Joseph has obtained from Madame six days' leave of absence, and
to-morrow he is to start for Cherbourg, pretending to be called by
family matters. It is decided; he will buy the little café. But for some
months he will not run it himself. He has some one there, a trusted
friend, who is to take charge of it.
"Do you understand?" he says to me. "It must first be repainted, and
made to look like new; it must be very fine, with its new sign, in gilt
letters: 'To the French Army!' And besides, I cannot leave my place
yet. That I cannot do."
"Why not, Joseph?"
"Because I cannot now."
"But when will you go, for good?"
Joseph scratches his neck, gives me a sly glance, and says:
"As to that I do not know. Perhaps not for six months yet; perhaps
sooner; perhaps even later. I cannot tell. It depends."
I feel that he does not wish to speak. Nevertheless I insist:
"It depends on what?"
He hesitates to answer; then, in a mysterious and, at the same time,
somewhat excited tone, he says:
"On a certain matter; on a very important matter."
"But what matter?"
"Oh! on a certain matter, that's all."
This is uttered in a brusque voice,—a voice not of anger exactly, but
of impatience. He refuses to explain further.
He says nothing to me of myself. This astonishes me, and causes me
a painful disappointment. Can he have changed his mind? Has my
curiosity, my hesitation, wearied him? Yet it is very natural that I
should be interested in an event in the success or failure of which I
am to share. Can the suspicion that I have not been able to hide, my
suspicion of the outrage committed by him upon the little Claire,
87. have caused Joseph to reflect further, and brought about a rupture
between us? But I feel from the tremor of my heart that my
resolution, deferred out of coquetry, out of a disposition to tease,
was well taken. To be free, to be enthroned behind a bar, to
command others, to know that one is looked at, desired, adored by
so many men! And that is not to be? And this dream is to escape
me, as all the others have? I do not wish to seem to be throwing
myself at Joseph's head, but I wish to know what he has in his mind.
I put on a sad face, and I sigh:
"When you have gone, Joseph, the house will no longer be
endurable to me. I have become so accustomed to you now, to our
conversations."
"Oh! indeed!"
"I too shall go away."
Joseph says nothing.
He walks up and down the harness-room, with anxious brow and
preoccupied mind, his hands nervously twirling a pair of garden-
shears in the pocket of his blue apron. The expression of his face is
unpleasant. I repeat, as I watch him go back and forth:
"Yes, I shall go away; I shall return to Paris."
He utters not a word of protest, not a cry; not even an imploring
glance does he turn upon me. He puts a stick of wood in the stove,
as the fire is low, and then begins again his silent promenade up and
down the room. Why is he like this? Does he, then, accept this
separation? Does he want it? Has he, then, lost his confidence in
me, the love that he had for me? Or does he simply fear my
imprudence, my eternal questions?
Trembling a little, I ask him:
"Will it cause you no pain, Joseph, if we do not see each other
again?"
88. Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.
More than just a book-buying platform, we strive to be a bridge
connecting you with timeless cultural and intellectual values. With an
elegant, user-friendly interface and a smart search system, you can
quickly find the books that best suit your interests. Additionally,
our special promotions and home delivery services help you save time
and fully enjoy the joy of reading.
Join us on a journey of knowledge exploration, passion nurturing, and
personal growth every day!
ebookbell.com