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() {
this._parent.buttonOneClick();
}
function buttonOneClick() {
trace("one");
}
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() {
trace("two");
}
Continue reading ‘Delegate works with plain old buttons too!’
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.
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 ‘Flash MX 2004 7.2 Updater — new Styling and Skinning information’
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 ‘Working with strongly typed variables and LocalConnection in ActionScript 2′
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.
Im posting this here in case anyone runs into a similar issue. In a recent application we built (All V2 based of course) we got a bug which turned out to be much harder to track down than initially anticipated.
Essentially what would happen is if a user clicked the up or down arrows on a scrollbar the player would stop executing any more code because of an infinite loop. After spending a lot of hours I tracked it down to an issue with the user clicking a ScrollBar’s up/down arrows which would in turn call the scrollIt() function inside of the ScrollBar class and somehow an infinite loop would occur (The ScrollBar in use was part of a ScrollPane). At first I tried to comment out the code inside of the scrollIt() function with no luck, then I tried just not calling scrollIt() which worked but didnt really help, I even tried re-writing some of the code of the ScrollBar class and also had no luck. At the end I ended up copying the scrollIt() functions code into a new function called scrollIt2() and calling that instead when the user clicks up/down and that worked. Why it worked I have no idea, I spent a few more hours after fixing it trying to narrow it down and couldnt find any logical reason for the bug and had to move on.
I’ll go back and look at it one day when I have some more free time and isolate the issue.
I’ve been accepted to speak at MAX again this year. I’ll be giving an updated version of the presentation I gave last year and at CFUN-04, Integrating with Microsoft Office.
I’m accepting questions or comments on what changes should be made–are there whole topics that should be discussed that weren’t? Were there things that should be dropped?
Right now it looks like I’ll be dropping the Authomation slides and am hoping to add an example using Jakarta POI and also of client-side communication between Flash and Excel.
You can view a Breezo of last year’s presentation and download the slides and examples here.