Archive for the 'Flex' Category

DisplayObject to JPEG or PNG with IImageEncoder

I work on a lot of charting and data visualization applications. Flex is great for these projects, but what happens when a client wants to use a chart (or any DisplayObject) from the application in a document, presentation, website or email? I needed a way to let users save jpeg and png files to their computers without storing any images on the server. The following solution works with PHP but it should be very simple to duplicate the process for other environments. Continue reading to try it out and view code.

Continue reading ‘DisplayObject to JPEG or PNG with IImageEncoder’

GroupingCollection -> HierarchicalCollectionView

This post is a continuation of “Distinct Data Providers with GroupingCollection.” The code and example is extremely similar - there are a couple minor changes to accommodate one addition: the use of HierarchicalCollectionView.

What’s new?

We saw in the previous post that a GroupingCollection works very well for creating a grouped data provider for an AdvancedDataGrid or even for use in part in a List or ComboBox control. But there’s a(nother/ better) way to populate that distinct List or ComboBox from the GroupingCollection. Use a HierarchicalCollectionView. It’s a more elegant solution and also lets you use your grouped data to populate a Tree or Menu control! Continue reading to try it out and view code.

Continue reading ‘GroupingCollection -> HierarchicalCollectionView’

Distinct Data Providers with GroupingCollection

Update: This post is updated and continued in the next post, “GroupingCollection -> HierarchicalCollectionView.” Please see that post for additional (better) suggestions.

This post is itself an update to “DistinctArrayCollection extends ArrayCollection.” The old post describes the problem and proposes a solution. I did not post code in that article because I felt like there had to be a better way of doing things. Here’s a better way (see the update for a much better way): use the GroupingCollection class in Flex 3. Continue reading to try it out and view code.

Continue reading ‘Distinct Data Providers with GroupingCollection’

DistinctArrayCollection extends ArrayCollection

Newest Update: Please read “GroupingCollection -> HierarchicalCollectionView” for a(nother/ better) solution to this problem.

Previous Update: Please read “Distinct Data Providers with GroupingCollection” for a solution.

Have you ever needed to display distinct items from an ArrayCollection based on a property of the objects in the collection? Here’s an example. An ArrayCollection populates a DataGrid with a list of people displaying the following properties: name, job and position. Beside the DataGrid you would like to display a distinct list of the jobs and positions from the data provider.

Continue reading ‘DistinctArrayCollection extends ArrayCollection’

Flex Part 03: The ModelLocator

The ModelLocator is an Action Script Class that is stored in the model directory.

This is a concept used in every Cairngorm application (see here for example) but you don’t need the Cairngorm library in your project to use it. In fact, you don’t need to know anything about Cairngorm to get started.

About the name

The ModelLocator holds instances of Model Objects, making them easy to locate and accessible from anywhere in the application.

Benefits of using the ModelLocator

The ModelLocator will make Flex development easier and more enjoyable. Here’s how: All application data will be stored in one single place, accessible from anywhere in the application at any time. That one place is, of course, the ModelLocator.

Continue reading ‘Flex Part 03: The ModelLocator’

Flex Part 02: Value Objects & Model Objects

Value Objects

Value Objects are ActionSrcipt classes which are stored in the project’s vo directory.

Think of a Value Object as a row in a database table. Let’s imagine a table named
schools with columns for name, phone, address and ranking. Imagine also a related table of students.

Table: schools (one school has many students)
+------------+---------------+
| Field      | Type          |
+------------+---------------+
| id         | Number        |
| name       | String        |
| phone      | String        |
| address    | String        |
| ranking    | Number        |
+------------+---------------+

Table: students
+------------+---------------+
| Field      | Type          |
+------------+---------------+
| id         | Number        |
| school_id  | Number        |
| name       | String        |
+------------+---------------+

Each row in the schools database table will have several properties which effectively describe a single School. The properties of a School contain simple values: strings, numbers, dates etc. This is the essence of a Value Object (VO).

Continue reading ‘Flex Part 02: Value Objects & Model Objects’

Flex Charting: Per-Item Fills

Get the Flash Player to see this player.

(Flex Charting is now Flex Data Visualization.)

Interested in how this was accomplished? Flex application located at the bottom of the post.

Continue reading ‘Flex Charting: Per-Item Fills’

Flex Part 01: Structure

The Flex Project Directory Structure

Structuring your code into manageable chunks is critical your sanity and the success of your project over time. The directory structure that you use will be largely influenced by the structural framework that you choose to employ (such as Cairngorm or PureMVC). I make a basic assumption throughout this series that readers will be using a Model View Controller (MVC) structure.

A Basic MVC Directory Structure


FlexProjectName <- Generated by Flex Builder
- libs
- src
— com
—- domain <- Replace with domain, ex: tsclausing
—– project <- Replace with project name, ex: blogdemo
—— control
—— model
——– vo
—— views
- Main.mxml <- Your default application file

This is a great place to begin your applications. We will not be using any structural framework libraries for quite some time in this series while still utilizing this directory structure. Other folders may exist at the same level as src and libs which are generated by Flex Builder when a new project is created. I won’t be focusing on those here.

Continue reading ‘Flex Part 01: Structure’