« August 2004 October 2004 »

September 22, 2004

What a week..

To say I've been busy lately is an understatement.

This week has been really hectic for me... On Monday I accepted a job offer for a Flash Development position and gave my final 2 weeks notice at work. In what used to be my free time I've been trying to pack everything I can and trying to find a new place to live, so all of my personal projects have been put on the back burner for now.

The job is in the Baltimore / Washington DC area, which is somewhere between 3 and 4 hours south of where I currently live. The distance makes it a little hard to "shop around," but I enjoy a good challenge. I've already found a nice apartment and I hope to finalize everything this weekend so I can move into it the week of October 3rd.

I've also been trying to polish up SolVE a bit. Until I move, I have a feeling I won't be making any more progress on it since I don't have the time in the evenings anymore.. but I already have some enhancements/fixes complete. A partial list:

  • Support for Arrays (Date, XML, etc. coming whenever I get time)
  • Fixed a problem with UTF-8 support for String values
  • Added French, Bulgarian, and Chinese translations, as well as a menu to change language on the fly. Special thanks to those who translated the resource strings (I need to give credit to them on the project page)
  • Fixed the starting path on Windows for "Open from Player Folder"

Sometime before the middle of October expect an update with at least those changes. I still need to apply for a sourceforge page (maybe I'll apply at tigris instead). I want to get the code out because I'd like other people to be able to contribute if they want. Java SWT is pretty fun developing in, too.

Additionally, the FedEx truck arrived today to drop off a package of Macromedia goodies. However, I wasn't home to sign the receipt form, so I'll have to wait until tomorrow to see if I got a Tweener shirt or a Goto And Play one. I already have a Goto And Play shirt from FlashForward, so hopefully I don't get a duplicate. If I do, I'll have to try and strike up a trade with someone!

So, now that you know probably more than you wanted to about what I'm currently up to.. I need to continue packing my things up. The next 2-3 weeks are going to be pretty quiet from me as I uproot myself from the Lehigh Valley and settle into the new home. I'm looking forward to trying to spend time with Ted, Chafic and Sam, Chief and Branden once I get settled since I know they're in the area.

A parting thought - If you run a PC, have you tried PearPC yet? Amazing little piece of software, hopefully it continues to improve. My next computer is going to be a Mac without question. A 1.3 GHz emulated G3 isn't fast enough.. :-)

September 13, 2004

Announcing SolVE

Eric Dolecki asked the question, Darron Schall answered.

I'm pleased to announce a preview release of SolVE v.1. SolVE is a local shared object viewer/editor that runs on both Mac OS X and Windows. Built in Java with IBM's SWT, SolVE looks and behaves like a native application - it should be transparent to the end user that SolVE is powered by Java under the hood.

Currently at version .1, SolVE is still under development but should be stable enough to start using regularly. Not all of the data types are supported yet (the more common ones that I use are), but I'm getting there... There are lists of things I want to do yet and some known issues I need to fix before the 1.0 release on the project page.

If you want to translate SolVE to another language, please let me know. I have almost all of the resource strings defined at this point, so translation should be relatively straightforward.

Full details (as well as download links) are available at the SolVE project page. Stay tuned for more updates...

September 02, 2004

Making Delegate earn it's keep...

By now everyone should have at least heard of the "mx.utils.Delegate" class that was included in the Flash 7.2 updater. This post is not intended to explain the Delegate class, but rather, here's a simple little trick showing how to use Delegate to pass additional information to generic event handlers.

Here's the scenario: A user is presented with two buttons. Each button increments a value by a different amount (either 1 or 5) when the button is pressed.

Programming this interaction is easy enough - we simply create two functions, incrementBy1 and incrementBy5, and proxy the events to the appropriate function. Part of the code for that might look like this:

btn1.addEventListener("click", Delegate.create(this, onIncrement1));
btn2.addEventListener("click", Delegate.create(this, onIncrement2));

However, this solution isn't ideal. We've created two distinct increment functions that perform basically the exact same task. In this situation, what we really want to do is create a single increment function, and pass the amount to increment as a parameter.

We can mimic this behavior by proxying both of the events to the same onIncrement function, examine the event's target's name property to figure out which button was pressed, and then increment by the value associated with that button. The code for the new onIncrement might look like this:

function onIncrement(eventObj) {
 	var which:Number;
 	
 	which = parseInt(eventObj.target._name.substr(3));
 	switch(which) {
  		case 1: total += 1; break;
  		case 2: total += 5; break;
  	}
 	
 	trace(total);
}

However, the problem with that is we're back to the reason that we wanted to proxy events in the first place! We don't want a generic event handler to have to determine where the event came from. Instead, we want the event handler to just "do it's thing" without worrying about context.

We can accomplish this by leveraging Function objects in Flash. Whenever you call Delegate.create, a function is returned. We can stuff properties into that Function object, and then access those properties from within the event handler by using the arguments.caller scope.

You can see this technique in action in the following complete code sample:

// 1) create a blank fla, drag a v2 button to the
// stage then delete the button instance so that 
// the button only resides in the library.
// 2) paste this code on frame 1 and test movie

import mx.utils.Delegate;
import mx.controls.Button;

function init() {
 	// create and place our buttons
 	createClassObject(Button, "btn1", 1, {label:"plus 1"});
 	createClassObject(Button, "btn2", 2, {label:"plus 5", _y: btn1._y+btn1.height});
 
 	// both buttons use the same onIncrement event
 	// handler - but the handler behaves differently
 	// based on the step value set
 	var f = Delegate.create(this, onIncrement);
 	f.step = 1;  // btn1 steps up by 1
 	btn1.addEventListener("click", f);
 	f = Delegate.create(this, onIncrement);
 	f.step = 5;  // btn2 setps up by 5
 	btn2.addEventListener("click", f);
 	
 	// initialize our running total
 	total = 0;
}

// generic increment function used as
// event handler for the buttons
function onIncrement() {
 	// grab the step property from the 
 	// delegate function we created, and use
 	// that as the increment value
 	total += arguments.caller.step;
 	trace(total);
}

init();

By using a generic increment function and using what I'll call "pseudo-parameters" we can easily add new buttons with different increment (or decrement) values. This enables us to easily reuse the code we already have and make maintenance easier.

In summary, we can pass parameters to a generic event handler using Delegate.create by stuffing data into the Function object returned by the create call and then using the arguments.caller scope in the event handler body to access that data.

More information on the Delegate class can be found here: Proxying Events with the mx.utils.Delegate Class