Category Archives: Flex

Don’t cast an UncaughtErrorEvent error

I just found this out the hard way, but you shouldn’t cast the error property of an UncaughtErrorEvent. I was doing the following in my uncaught error event handler:

1
2
3
4
5
6
7
8
9
private function onUncaughtErrorEvent(event:UncaughtErrorEvent):void {
	event.preventDefault();
	event.stopImmediatePropagation();
	if(event.error is Error) {
		log(Error(event.error).getStackTrace());
	}else if (event.error is ErrorEvent) {
		log(ErrorEvent(event.error).text);
	}
}

The problem with this is that it returns your uncaught error event handler as the last step when you call getStackTrace(). But changing your code a little will give you the real source of your error. Maybe everyone else knew this already, but I’m logging it here on my blog so I don’t forget.

1
2
3
4
5
6
7
8
9
private function onUncaughtErrorEvent(event:UncaughtErrorEvent):void {
	event.preventDefault();
	event.stopImmediatePropagation();
	if(event.error is Error) {
		log((event.error as Error).getStackTrace());
	}else if (event.error is ErrorEvent) {
		log(ErrorEvent(event.error).text);
	}
}

Namespaces on Attributes with E4X in ActionScript 3

I recently came accross an odd behavior when adding namespaces to an attrubute using E4X. I needed to create an XML object like the following:

1
<body xml:lang="en" xmpp:version="1.0" xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:xmpp="urn:xmpp:xbosh" />

This XML element is created dynamically within the ActionScript code like this:

1
2
3
4
5
var body:XML = <body />;
var xml:Namespace = new Namespace("xml", "http://www.w3.org/XML/1998/namespace");
body.@xml::lang = "en";
var xmpp:Namespace = new Namespace("xmpp", "urn:xmpp:xbosh");
body.@xmpp::version = "1.0";

However, the output of the namespaces in the XML was off:

1
<body aaa:lang="en" aab:version="1.0" xmlns:aaa="http://www.w3.org/XML/1998/namespace" xmlns:aab="urn:xmpp:xbosh" />

I realize this is still valid, but the server was having issues with it. That’s when I discovered that I need to first add the namespaces to the XML element using addNamespace(). This then gave me the right output:

1
2
3
4
5
6
7
var body:XML = <body />;
var xml:Namespace = new Namespace("xml", "http://www.w3.org/XML/1998/namespace");
body.addNamespace(xml);
body.@xml::lang = "en";
var xmpp:Namespace = new Namespace("xmpp", "urn:xmpp:xbosh");
body.addNamespace(xmpp);
body.@xmpp::version = "1.0";

Hopefully this will save someone else an hour of banging his or her head against the wall.

Speaking about Flash Development on Facebook

Flashbelt 2010I’ll be speaking at a couple confirences in the next six months on the topic of Flash Development on Facebook. The first conference I’ll be at is MN.swf Camp on April 5th. This will be a short 30 minute session that will introduce the concepts around developing a Facebook application and specifically putting Flash Applications within Facebook.com.

Then I’ll be giving a much more in-depth session at Flashbelt in June. This session will actually dig into some of the details and caveats of Facebook development. Patterson Consulting has been doing a lot of Facebook integration with our clients lately and we see this as an emerging market Flash developers.

BusinessCard2.com using Flex to Distribute Business Cards

For the past few months I’ve been working with the guys over at Workface to develop their BusinessCard2 platform. BusinessCard2 is a fast growing social site that is focused on being your professional identity online. Simply go the BusinessCard2.com and enter in your contact information to create your card. Then you can embed the card on your web site or blog, you can share it on a number of social web sites, and you can even sign up for the AdCast service where BusinessCard2 will actually purchase advertising space and push your card to a number of publishers on a cost-per-interaction basis.

Continue reading

Upload ByteArray to Flickr

If you’ve used the the AS3 Flickr Library for uploading images to Flickr you know that it requires a FileReference object. Since you can only get a FileReference if you ask the user to browse to a local image on their hard drive or if you’re using AIR and just grab an image from the user’s hard drive. But what if you just want to upload a dynamically generated image from within your SWF?

Continue reading

Transparent Background Image in Flex

Here is a quick tip for setting a transparent image as the background of your Flex application. If you want that transparency to pass through to the HTML page you would set your wmode to “transparent.” But even after you set your transparent background image you’ll notice that default blue background still shows through. And yu can’t set the backgroundAlpha to 0 since that would also hide your background image. What you need to know is that the backgroundColor is defaulted to that blue color, so you must set the backgroundColor to undefined so your application has no background color:

1
2
3
4
Application {
    backgroundImage: Embed(source="/assets/Background.png");
    backgroundColor: undefined;
}

SharedObject Best Practices

I downloaded the Hulu Desktop application today and when it threw a runtime error (since I have my shared objects disabled by default) I decided it was finally time to blog about best practices when working with Shared Objects.

First, your code should never be “dependant” on a Shared Object being set. The user has full control to disable Shared Objects just like they can with browser cookies. If it absulutely must be set, then you should at least show a graceful degredation to the user explaining that they won’t get the full expereince without enabling shared objects.

Second, you should allways put your shared object code inside a try…catch statement. If the user does have Shared Objects disabled by default, a runtime error will be thrown (and shown if they have the debug player) when you try to write to a Shared Object.