Category Archives: Flash

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);
	}
}

Yahoo World Cup Game

I don’t do many games, but I recently worked with Sapient to build a World Cup game for Yahoo. The game is a multi-player Penalty Shootout. It lets you invite and challenge your friends to matches or you can “play now” against a random player from around the world. This game has been localized for 17 different countries and languages. At the end of the World Cup Yahoo will even be give out a great prize to one of the top players in the game. There were lots of challenges in creating this game, but it was fun and the teams and Sapient and Yahoo were great to work with. Check it out!

Yahoo Penalty Shootout

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.

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

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.

Adobe's Flex Builder rebranded as Flash Builder

As you may have heard, Adobe has decided to rebrand Flex Builder as Flash Builder to go along with the Flash Platform initiative. I actually think this is a really good idea. Flash Player has always been the platform and the vehicle that has allowed developers to deliver amazing experiences for years. Flex is a great framework that I personally use on 90% of my projects, but I don’t think the IDE (Flash Builder) should be limited to a single framework.

The only problem I have with the name change is that it doesn’t go far enough. When I say Flash, what is the first thing you think of? If you’re a Flash developer, you probably think of Flash Professional. This is an authoring tool that has been around for years and until Flex Builder it was our only “Adobe” tool for creating SWFs. It’s NOT a programming tool. Therefore most Flash programmers welcomed Adobe’s attempt at a real programmers IDE with Flex Builder. It isn’t perfect, but it’s better than any alternative. (Yes I’ve tried FDT, but I can’t live without the debugger.)

So my problem with the new Flash branding is the name of Flash Professional. This tool is based on a timeline and is geared toward designers. I personally think this should be renamed to Flash Designer. This would help reduce confusion for new developers to the Flash Platform and put clarity into the entire Flash product line.