Building Blocks

17Jul/096

Robotlegs AS3: A Dependency Injection Driven MVCS Framework for Flash/Flex – Inspired by PureMVC

robotlegs.org

robotlegs best practices

The quest for a Dependency Injection container continues. The most recent stop on this exploration of the available options has been Robotlegs. Robotlegs AS3 is a DI driven MVCS framework for Flash/Flex inspired by PureMVC. Being a huge fan of PureMVC, this caught my attention immediately. Robotlegs professes to be a framework like PureMVC, but without all the Singeltons, Service Locators, casting and boiler plate we have all come to love. Better yet, it delivers on these claims.

Source for this demo available on github...

Get Adobe Flash player

14Jul/097

Inversion of Control and Dependency Injection with Flex using the Parsley Application Framework – Part 2

This is the second part in a series exploring Inversion of Control and Dependency Injection containers available for Flex. In the first part of the series we discussed what IoC and DI are and how they can benefit our applications. In this part, we will explore the Parsley IoC Container through a simple image gallery application.

Here's the source on github...

Get Adobe Flash player

The above is a simple image gallery that is grabbing the top 100 'interestingness' images from Flickr. It is built with Flex 4 and uses a mix of halo components (the images) and spark components for layout. Parsley in its current state does NOT support the Flex 4.0.0 SDK. It IS however opensource, and only required a single change to function in Flex 4. Namely, there is a call to Application.application which has been 'deprecated' (and by that they mean completely broken) and replaced by FlexGlobals.topLevelApplication. The modified SWC files are included in the source repository for the project. The modified swc files WILL NOT function with Flex 3.*.*
18May/0920

Piping the Machine: PureMVC Multicore with Pipes and the Finite State Machine (FSM)

This is going to be a walkthrough of making use of PureMVC Multicore (AS3). To help in building a PureMVC Multicore application, we are going to make use of the StateMachine utility for initial setup and configuration as well as the Pipes utility for communication between cores.

Here's the Source.

Get Adobe Flash player

18Apr/097

Pleat Menu – Flex Component (draft)

The Pleat menu that is used in Buzzword is really sweet. I wanted to emulate in an attempt to get a reusable component along the same lines. This is the first draft at my attempt, and it admittedly needs some work, but it is still useful, even in its current state.

Here's the source.

One of my goals with this is to have all the actual controls in the Pleat available at the top level. This makes it a lot easier to capture in PureMVC (or your event/notification system of choice) and doesn't bury the components. I want to go in and refactor it some more to emulate the Adobe set of Flex components. We'll see if I have the time ;)

the icons are from the awesome fugue set found here.

Filed under: components, flex 7 Comments
16Mar/093

The Flickr AS3 API and Flex

We've been using wordpress for our family photo blog for years. It worked well, 4 images in a horizontal scroll. It was kinda tough to navigate though. If you were looking for an image you had to click more... more... more... etc through 3 or 4 years of photos. I wanted something easier to update and navigate. I also wanted to play around with the Flickr API. Luckily the Adobe Flickr AS3 library is very complete. Unfortunately it is very lacking in examples, but the API is well documented so it didn't take too long to get my bearings.

Here's what I came out with. Really it is meant to fill the browser, so check it out here too if you are interested. Source is enabled on the movie. Codes sloppy, but it gets the job done. ;)

Filed under: actionscript, flex 3 Comments
5Feb/091

Debugging your AIR/Flex application with Arthropod

Arthropod is an external Debug trace window for Flash/Flex/AIR. Drop a simple class into your project and it will accept logging from the application/swf. I'm using it for debugging around the office with our internal project management AIR application with great success.

Filed under: AIR, flex 1 Comment
1Feb/0927

Form Validation for the Lazy Programmer in Flex

Forms... Any data-centric application is going to have its fair share of them. They are fairly tedious work. Layout out the form, manage the output, validate the output, over and over. Validation is best when it is active, to let the user know that they have made a mistake before they try to submit the data. Optimally the user won't be allowed to continue until the form data is complete and accurate.

Every form I've written carries the same structure for validation, so as a dedicated lazy programmer I wrote a simple FormValidator class to handle the boilerplate.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.visualempathy.validators
{
	import flash.display.DisplayObject;
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
 
	import mx.events.ValidationResultEvent;
	import mx.validators.Validator;
 
	[Bindable]
	public class FormValidator extends EventDispatcher
	{
		public var formIsValid:Boolean = false;
 
		public var validators:Array;
		private var focusedFormControl:DisplayObject;
 
		public function FormValidator(target:IEventDispatcher=null)
		{
			super(target);
		}
 
		public function validateForm(event:Event):void
		{
			focusedFormControl = event.target as DisplayObject;
			formIsValid = true;
 
			for each( var validator:Validator in validators )
				validate(validator);
		}
 
		private function validate(validator:Validator):Boolean
		{
			var validatorSource:DisplayObject = validator.source as DisplayObject;
			var supressEvents:Boolean = validatorSource != focusedFormControl;
			var event:ValidationResultEvent = validator.validate(null, supressEvents)
			var currentControlIsValid:Boolean = event.type == ValidationResultEvent.VALID;
 
			formIsValid = formIsValid && currentControlIsValid;
			return currentControlIsValid;
		}
	}
}

in the MXML I add an Array structure to hold the Validators, and add the FormValidator like so:

1
2
3
4
5
6
7
8
9
10
	<mx:Array id="validators">
		<mx:StringValidator id="studioNameValidator" source="{this.studioNameInput}" property="text" required="true"/>
		<mx:EmailValidator id="emailValidator" source="{this.emailInput}" property="text" required="true"/>
		<mx:PhoneNumberValidator id="phoneValidator" source="{this.phoneInput}" property="text" required="true"/>
		<mx:StringValidator id="addValidator" source="{this.addressInput}" property="text" required="true"/>
		<mx:StringValidator id="cityValidator" source="{this.cityInput}" property="text" required="true"/>
		<mx:StringValidator id="stateValidator" source="{this.stateInput}" minLength="2" maxLength="2" property="text" required="true"/>
		<mx:ZipCodeValidator id="zipcodeValidator" source="{this.zipcodeInput}" property="text" required="true"/>
	</mx:Array>
	<validators:FormValidator id="formValidator" validators="{this.validators}"/>

This allows you to add an arbitrary number of validators. Then in the various inputs:

1
<mx:TextInput id="studioNameInput" text="{this.studio.name}" width="100%" change="this.formValidator.validateForm(event);"/>

with the button to commit the changes enabled only when the form is valid:

1
<mx:Button id="saveChangesBtn" label="save" click="handleSaveChanges()" enabled="{this.formValidator.formIsValid}"/>

It reduces some of the pain and tedium with the process of creating forms, which is always welcome.

Filed under: components, flex 27 Comments
24Jan/095

Adding a ToolTip function to a ComboBox in Flex

My screens get a bit crowded sometimes, especially when dealing with forms. Users want to be able to see additional information, but there is just no place to put it. The data is dynamic though, so the toolTip needs to change based on the currently selectedItem of the ComboBox. With a DataGrid, for example, you have a showDataTip property on a column and can assign a dataTipFunction. There is no similar function in the ComboBox, but it is easy enough to add. I'm also using the HtmlToolTip class for a little extra style in the ToolTip itself.

View Source is enabled.

19Dec/083

Introspective PureMVC Console

This project is intended to help Flex and AS3 application developers, that use the PureMVC framework for AS3 - simple or multicore version - by providing them deep insights on what happens at the framework level: Notifications, Commands, Mediators and Proxies.
PureMVC is a highly recognized MVC framework, that has also many portages in various languages, and that's now quite widely in Flex applications, though not as much as Cairngorm.

What a fantastic tool. You can really dig deep into your application.

  • Monitors the internal flow of PureMVC in real time
  • Discover and inspect Mediators
  • Inspect Views associated to Mediators
  • Discover and inspect Proxies
  • Find starting point in source code
  • Integrated with KapInspect

http://lab.kapit.fr/display/puremvcconsole/PureMVC+Console

6Dec/088

ImageSwap (crossfade) Flex Component

I needed a component that would work in my slideshow component and give a decent crossfade while letting the user know that something was going on. I used TweenLite for the tweening, and it works pretty well. It dispatches an 'imageLoaded' event when the image swap has completed. I needed this so that the slideshow timer can resume. It pauses when the image starts loading because of various image sizes/connection speeds. Pretty simple, but it is a lot nicer than the harsh transition (or lack of) in the current slideshow.

Source Here.

Filed under: components, flex 8 Comments