Joshua Noble
Created
10 November 2008
User level
Beginning
 
 
The best way to showcase a powerful new technology is to demonstrate its real-world results, and that's exactly what this new Cookbook does with Adobe Flex 3.
 
Wide ranging and highly practical, Flex 3 Cookbook contains more than 300 proven recipes for developing interactive Rich Internet Applications and Web 2.0 sites. You'll find everything from Flex basics, to solutions for working with visual components and data access, to tips on application development, unit testing, and using Adobe AIR.
 
You also get ideas from the development community. Through its Flex Cookbook website, Adobe invited Flex developers to post their own solutions for working with this technology, and from hundreds of posts, the authors chose the best and most useful solutions to supplement Flex 3 Cookbook.
 
Each recipe inside provides a solution to a common problem, explains how and why it works, and offers sample code that you can put to use immediately. Topics include:
 
  • Containers and dialogues
  • Working with Text
  • Data driven components
  • DataGrid and Advanced DataGrid
  • ItemRenderers and Editors
  • Images, bitmaps, videos, and sounds
  • CSS, styling, and skinning
  • States and effects
  • Working with Collections, arrays, and DataProviders
  • Using DataBinding
  • Validation, formatting, and regular expressions
  • Using Charts and data visualization
  • Services and Data Access
  • Using RSLs and Modules
  • Working with Adobe AIR
Whether you're a committed Flex developer or still evaluating the technology, you'll discover how to get quick results with Flex 3 using the recipes in this Cookbook. It's an ideal way to jumpstart your next web application.
 
The printed book is available through most major online and retail bookstores worldwide, and can be read online at Safari Books Online. For more information visit the O'Reilly store.
 
Copyright © 2008, Joshua Noble and Todd Anderson. All rights reserved.
 

Images, bitmaps, videos, sounds

Images, bitmaps, videos, and sounds is a mouthful and a far wider range of topics than could be adequately covered in a single chapter, so this one concentrates on answering the most common questions. As Flash becomes the primary method of delivering video over the Internet and the use of the Flex Framework in creating photo and MP3 applications increases, understanding how to work with all of these elements becomes more and more important.
 
The Flash Player offers multiple levels of tools for dealing with images and sound. The first avenue of control contains the Image and VideoDisplay classes, MXML classes that simplify much of dealing with images and video and enable you to quickly integrate these assets into your application. The next step down is the flash.media package, which houses the Video, Sound, SoundTransform, Camera, and Microphone classes; their corollaries, Loader, NetConnection, and NetStream, are in the flash.net package. These classes provide much finer control over the integration of sound, video, and images into an application and require slightly more time to perfect. Finally, you can reach down to the bytes that make up all data in the Flash Player: the BitmapData classes and the ByteArray classes. These enable you not only to manipulate the bitmap data of the images that you load into the Flash Player, but also to create new bitmaps and stream the data out.
 
Many of the examples in this chapter manipulate images and videos as bitmap data. This is not nearly as difficult as it sounds, because the Flash Player provides numerous convenience methods for working with the BitmapData class, and manipulating the bitmap data directly greatly increases the efficiency of your application. You'll also be working extensively with the NetStream class, for handling video and users' microphones and cameras. NetStream is an effective way of streaming information both to and from server-side applications.
 
Download the complete chapter

Unit testing with FlexUnit

Unit testing is a practice and concept that has been slowly gaining in popularity and acceptance in the Flex community as Flex applications have grown larger and more complex. Unit testing, the process of ensuring that new additions or changes to a project do not introduce bugs or modify expected behavior, enables large teams to work in tandem without introducing bugs and confirm that small individual parts of a program, down to specific methods, all return the expected results. This lets bugs and errors be pinpointed much more quickly, because a properly written unit test will test the behaviour of a single method or a very small piece of functionality.
 
The core of unit testing is the test case, an evaluation that passes a value into a method of an application and reports the test as passing if the correct value is returned. These can be as simple as checking whether a method returns the correct integer value for an operation or as complex as ensuring that some display logic is appropriately performed or that a service has returned the correct object type. Many test cases taken together are referred to as a test suite, a group of test cases that can test an entire application or a specific aspect of a very large application. The test suite will show all test cases that have passed or failed. As a developer adds new code to the application, new test cases are written to provide coverage for that new code and are added to the test suite, and then the entire test suite is run. This ensures that any added code does not interfere with previously functional code and that the new code integrates as expected with the application.
 
The FlexUnit Framework allows you to create test cases and asynchronous tests and evaluate test suites in a test harness application that provides a visual display of all the tests in that test suite. The recipes in this chapter, all of which were written and developed by Daniel Rinehart, show how to develop meaningful test cases and integrate them into coherent test suites, as well as how to use more-advanced tools like the Antennae library that assist in automatically generating tests as you develop your applications.
 
Download the complete chapter

Compiling and debugging

Compiling Flex applications is most often done through Flex Builder or through invoking the MXML compiler (mxmlc) on the command line, but there are many other tools that let you compile an application, move files, or invoke applications. Tools such as make, Ant, or Rake, for example, enable you to simplify an entire compilation and deployment routine so that you can invoke it from a single command.
 
Debugging in Flex is done through the debug version of the Flash Player, which enables you to see the results of trace statements. With Flex Builder 3, you can step through code line by line and inspect the properties of variables. Flex Builder 3 also introduces a new profiling view that lets you examine memory usage and the creation and deletion of objects. Outside of Flex Builder, numerous open source tools expand your options. With Xray and Console.as for Firebug, for example, you can inspect the values of objects, or you can view the output of trace statements with FlashTracer or the Output Panel utility instead of using the Flex Builder IDE. The recipes in this chapter cover debugging with both the tools provided in Flex Builder as well as tracing values and inspecting objects by using Xray and FlashTracer.
 
Download the complete chapter