Minor Bug with Bitmap Smoothing in AS3

We recently encountered a problem where bitmap images that we created dynamically were not being properly smoothed when rotated and scaled. We couldn’t see any obvious reason for it – we were setting the container bitmap to smooth, tried every quality setting, but it still looked terrible.

The answer turned out to be super simple, if not immediately obvious. The Bitmap object in ActionScript 3 reverts its .smoothing property to false whenever you change it’s .bitmapData property. Because we were setting up our Bitmap objects in advance, then assigning BitmapData objects to them when they were created, it simply appeared as though smoothing just didn’t work in our project.

Continue reading →

SCPlugin updated: SVN Support for OSX

The awesome folk working on SCPlugin for OSX have just released the 0.7 update. I haven’t started using the update yet (downloading it now), but from the release notes it looks like a great release that should provide pretty much all the functionality Mac ActionScript developers will require in day-to-day Subversion use. The most significant updates:

– Accepts user name and password. No more need for a separate command-line copy.

– All the major commands work. Everything in the menu works.

Previously, we’ve used a combination of SVNX for creating repositories, SCPlugin for commits and updates, and the command line for more advanced tasks. Looks like with this release we can stick with just SCPlugin, and the occasional command line operation.

If you’ve been trying to find a good Subversion/SVN client for the Mac, this should be it. I know source control has been a missing part of the puzzle for a lot of Flash and Flex developers who have switched to OSX.

You can read more, and download the installer (also new, no more manual install) from here.

Annoying AS3 Bug with rotation and height/width

I found a very problematic and reproducible bug with ActionScript 3 and simple display object transformations (width, height, rotation), and thought I should document it to save other developers some debugging time.

Put a 200x200px square clip on stage named foo. Add the following code.

foo.height = 100;
foo.rotation = 90;
trace(foo.height);

As expected, this traces 200. It scales the clip vertically, then rotates it, so that it is now 100px wide and 200px high on stage. Now, change the code, and run it again.

foo.rotation = 90;
foo.height = 100;
trace(foo.height);

Unexpectedly, this also returns 200. It should rotate the clip and then apply the vertical scale resulting in a shape that is 100px high and 200px wide on stage. The visual result is identical to the above, when it shouldn’t be.

foo.rotation = 90;
foo.height = 100;
foo.height = 100;
trace(foo.height);

Even stranger, this does trace 100. Unfortunately, the object has been scaled both vertically and horizontally, and is now 100x100px, when it should be 200px wide and 100px high. Seems like the first height assignment gets applied before the rotation, and the second gets applied after the rotation.

Click here to see a (very) simple demo of this behaviour. The left and right blocks should be the same dimensions.

Freaky. I would hazard a guess that this is related to AS3’s weird hybrid of display object properties and transform matrixes.

One workaround would be to work with scaleX and scaleY instead, which are always applied to the original dimensions, and do not account for rotation.

My New Puppy. So cute!

I don’t usually post personal content, but for a puppy, I’ll make an exception. I mean, who doesn’t like puppies?

On Wednesday we picked up our new Bugg (Boston Terrier / Pug cross) puppy and brought him home. He’s named Gir (pronounced grrr), both because he acts a bit like GIR from Invader Zim, and just because I think it’s a cool dog name. Bobi says she’s going to try to make him a green GIR suit one day, though she won’t let me name our future cat Pir. 🙁

Photos after the jump.

Continue reading →

AS 3 Workshop in Toronto with Grant Skinner

I’ve had a lot of people asking me when I’m going to run another workshop, so I thought I should post about it here.

On September 25th, I will be running a one day workshop in Toronto on Introductory ActionScript 3, in partnership with FitC and RMI. As with all my workshops, it will pack a ton of content into the time available (if you don’t leave with a headache, I don’t feel like I’ve done my job), starting with basic AS3 and proceeding quickly into more advanced topics like data loading and parsing, display list management, nitty gritty details on the event model, and more. I’ll also be doing a brief introduction to Flex 3, Flash CS3 and AIR, to get attendees prepared to ask really tough questions at the Adobe onAIR event the next day.

This workshop is targeted at developers with a working knowledge of ActionScript 2, and/or some basic experience with AS3.

We have limited seating available for this workshop, so if you’re interested be sure to sign up. Punching “gskinner” in as the discount code will get you $25 off. If you’re planning to send a few people, fire me or RMI an email and they might be able to hook you up with an even better discount. A full description, and registration information is available here.

If you have any questions about the workshop, feel free to ask in the comments below.

FAVideo Released: Flash Video for JavaScript / AJAX

We had the pleasure of working with Adobe to architect and develop the FAVideo component that Kevin Lynch demoed at AJAXExperience, and which was just released in beta form on the Adobe labs site. It was an interesting project, building a Javascript object that acted as a facade for an embedded Flash video player, and using external interface to communicate between them. The intent is to provide a simple interface for AJAX / Web2.0 developers to embed, control, and play video back in their applications. As such, it has a really robust API for controlling video playback, but it also provides a really simple way for anyone to quickly inject video into their HTML content.

<script lang="javascript">
// simple usage:
var myVideo = new FAVideo("myDiv", "myVideo.flv");
// or a little more customized:
var opts = {skinPath:"SteelOverAll.swf", autoLoad:false, previewImagePath:"preview.jpg"};
var myVideo = new FAVideo("myDiv", "myVideo.flv", 320, 240, opts);
</script>

We had to write some interesting logic to deal with delaying method calls while the player SWF loads, as well as writing a custom event model for subscribing to events like cuePoint, progress, and playheadUpdate in Javascript. We also included support for using any Flash 8 video player skin, youtube-style preview images, built-in Flash player detection, and a ton more. Building the Javascript portion of this component was a somewhat nostalgic experience for me, hacking out classes using prototypes. Made me even happier about AS2 & 3.

The trickiest part of the whole thing was getting it to work properly in Internet Explorer. Apparently there’s a series of nasty issues with IE, Flash player, divs and innerHTML – but that’s a topic for another post.

FAVideo is released under a BSD license, so it can be used for commercial projects. You can download the full source on Adobe Labs. Thanks to everyone at Adobe that tested and provided feedback on the component!