Delegate works with plain old buttons too!

We’re working on a rush project and to save time are using our designer’s mock-up as a starting point (we usually re-create it from the ground up). One issue is that he occasionally uses plain old Flash buttons instead of Button components because you can’t instance skin a button on stage.

In order to work with these buttons we usually use a simple onRelease handler that calls a function on _parent, as in the following example.

buttonOne.onRelease = function() {

function buttonOneClick() {

But after a little experimenting we found that the new mx.utils.Delegate class included with the Flash MX 2004 7.2 Updater can be used with plain old Flash buttons too, not just components. The following example is a little cleaner.

import mx.utils.Delegate;
buttonTwo.onRelease = Delegate.create(this, buttonTwoClick);

function buttonTwoClick() {

Continue reading

Advantages of the new mx.utils.Delegate class over EventProxy classes

The Flash 7.2 updater includes a new utility class, mx.utils.Delegate. This very useful class is used to redirect event handlers so you can subscribe to one event and have the component call a method by a different name in your class. For example, if you have a save button and a cancel button, the Delegate class makes it easy to call saveClick and cancelClick in your class instead of just a single click method and having to determine which button was clicked.

Many of us already had custom classes that accomplished the same results, often called EventProxy. However, it is worthwhile to replace usage of those classes with Delegate because Delegate has a major advantage: compile time checking.

In most previous iterations of EventProxy, including my own, the proxy was created by specifying the method to call as a string. However, the Delegate asks for the method to be specified as a reference. Therefore the Delegate instantiation involves compile-time checking and can help reduce errors.

For more information on mx.utils.Delgate, read Mike Chamber’s “Proxying Events with the mx.utils.Delegate Class” article on DevNet.

If you don’t already have it, download the free Flash 7.2 updater.

Flash MX 2004 7.2 Updater — new Styling and Skinning information

The Flash MX 2004 7.2 updater, code-named Ellipsis, was released today. The update incorporates both new help content and is coordinated with new DevNet articles. Chafic and I were very pleased to be involved with the updater and provided updates to the styles and skinning documentation and Chafic wrote an article for DevNet on skinning.

The doc updates include both a major re-write of the Using Components > Customizing Components chapter and updating the table of supported styles and skins for all components in the component dictionary. Some notable additions are the discussion of customizing animations and a new entry in the Component Dictionary on Rect Border.

One of the nicest additions is five interactive SWFs that are used to demonstrate some areas that are not easy to explain fully in text. For example, there is an interactive swf that shows the over 100 different button state combinations and one that shows the 98 different border property combinations, shown below.

Along with the documentation updates Chafic has a great skinning article on DevNet, Skinning the Flash MX 2004 Components that talks about the skinning architecture and gives examples of different approaches to skinning.
Continue reading

Working with strongly typed variables and LocalConnection in ActionScript 2

Oddly the LocalConnection class is not defined as dynamic in the ActionScript 2 intrinsic classes, even though the documentation demonstrates dynamic usage as an example of the LocalConnection class.

However, the fact that it is not declared dynamic can be turned into a positive thing and force us to use good OOP practices instead. Normally when we use LocalConnection we create an instance and then assign a function on that instance. This method of declaring functions should be avoided in AS2 as it violates several core concepts in object oriented programing.

The better way to implement LocalConnection is to create a class that extends LocalConnection and adds the functions you need in your application. That way you can strongly type the instances to your extended LocalConnection class and still benefit from all the advantages of AS2.

Here’s an example of a LocalConnection subclass we used in a recent application.

Continue reading

FlashForward 2004 this week

I’ll be in NYC for FlashForward towards the end of the week this week. I will be in town from thursday afternoon till saturday and will only be attending the conference on Friday. I’m really looking forward to Jared’s session, it’s his first time speaking and am sure it will be very intersting.

Also I have been too busy to keep up with what friends will be attending so drop me a line sometime this week so we can meet up.