Flex/Flash/Actionscript

The making of TileUI

I’ve posted a video that shows the progress that I made during the first 12 days of working on TileUI. For about the first 2 weeks I saved a snapshot of the progress I had made (I tried to save a snapshot each day, but I missed a few). The video below is a combined video of each of these, it starts at day 1 and goes through day 12.

I stopped taking daily snapshots (and I stopped making much progress) after the first two weeks because I started working on a contracting gig. I’ve gotten much further with the software now (as the previous AIR demo video shows). But I’m not making the day to day advances like I did the first few days (man, if only I could be unemployed forever).

Here’s a quick breakdown of how things went:

Day 1: Learn Actionscript Physics Engine. By the end of the day I had a decent physics simulation running that allowed me to throw around particles. Prior to this project I had never worked with APE, it’s a solid physics engine (my only complaint is how CPU intensive it is).

Day 2: Learn PaperVision 3D. Combine PaperVision with APE. Prior to this I hadn’t played with PV3D and I figured it was about time I learn. By the end of the day I had figured out the basics of PV3D and managed to map APE particles to 3D tiles in PV3D. Damn, these libraries are good.

Day 3: I got the tiles to display images. And I got the basic selection system working where you can lasso a set of tiles and they get grouped. The group was just a messy group of tiles, but it was a start.

Day 4: Added Flickr support to load tiles straight from Flickr. Added dynamic sizing of tiles.

Day 6: Made grouping tiles put them into 3D stacks. Added double clicking tiles to do something based on the tile content, ie open larger Flickr image. (I don’t remember why I don’t have a day 5 or 8 snapshot)

Day 7: Improved Flickr support, ability to page through results, load multiple search results, etc. Added spiral stack.

Day 9: Added the menu system. Added the twist menu item to twist a stacked pile. Allowed breaking piles you made.

Day 10: Added the fan layout method.

Day 11: Added the grid layout method.

Day 12
: Added the leafing layout method.

So what?
I thought this was cool because it shows a) how awesome and fast developing in Flex/AS3 is and b) how badass open source community libraries for Flex are. I was able to grab these open source libraries and within a few days have something pretty sweet to show for it. A big thanks to everyone behind the PaperVision project, and to Alec Cove for the APE engine. You guys make this stuff easy.

At last count I am using 10 different open source libraries in the TileUI project in one way or another.

Standard
Flex/Flash/Actionscript

Coming to FlexCamp at Adobe?

I’ll be at Adobe this Friday for the FlexCamp event. If you’re there then find me and say hi (sadly no mohawk at the moment, so I’m not as easy to spot). I’ll probably be one of the people drinking in the back. I don’t know how the whole sessions thing is going to work. I suggested a session on the FlexCamp wiki to talk about Flex community libraries (like FlexLib, Papervision, etc). So I have no idea what the deal will be in terms of these attendee-suggested sessions, but people on the wiki have shown some interest in the community library session, so if you want to come talk about all the cool libraries that are available I guess we’ll try to do that at some point in the night.

If you want to play with tileUI I’ll have a demo (both as a web-based Flex app and a desktop AIR app) you can try to throw tiles of your face all over the place.

This movie requires Flash Player 9.

Standard
Flex/Flash/Actionscript

I’m on the Flex Show!

The Flex ShowThe first half of my interview for the Flex Show is up online. Listen to me blabber. We go over 360Flex, FlexLib, a bunch of open source Flex libraries, and I talk about my thoughts on Flex component development.

We had some technical issues (all my fault). My mic wasn’t nearly as good as Jeff’s, which is pretty clear in the audio. And my internet connection was piss-poor, so while he could hear me just fine, I only heard bits and pieces from Jeff’s end, which made it a little difficult to have a conversation. I think Jeff edited it a bit to make it sound like we were actually talking, but often he asked a question and I waited for him to type it out before I could answer it. And to top it all off my recording program froze up before the end of the interview, so the last bit is a backup recording that Jeff thankfully made. But what else do you expect from a tech podcast? 🙂

Standard
Flex/Flash/Actionscript

FlexLib in the wild

I’ve started noticing FlexLib components out in the real world. It’s a pretty cool feeling to launch some Flex app and suddenly realize that some component you wrote is being used. Here are a couple of screenshots of a few Flex apps that I’ve seen using a few components from FlexLib.

salesbuilder_flexlib_supertab.jpg

Salesbuilder demo app by Christophe Coenraets
Uses the SuperTabNavigator. This is a great use the SuperTabNavigator. By setting the tabs to be rectangular and skinning the close button on the tabs, it ends up looking great. Download the air app, play with it, and notice how super the tabs really are.

synchronicity_flexlib_supertab_prompting.jpg

Synchronicity
by Eric Cancil and team (sorry, I only know the name of the guy who blogs it)
I was using this app to test it out and watch some recorded performances and then I noticed that the tabs use the SuperTabNavigator (see those blue tabs with the close button?). I also noticed that the form fields use what looks like the PromtpingTextInput control (see the fields that say Firstname, Lastname, and City?).

agile_flexlib_accordion.jpg
AgileAgenda by Marc (don’t know last name)
Uses the Horizontal Accordion.

Also, I just started a contract working with a Flex startup here in the Bay Area. When I got set up with the project files I noticed that in the /lib directory was flexlib.swc 🙂 They’re using the Highlighter component.

If you’re using a FlexLib component in a Flex app, I’d love to know about it. Send me an email if you want. It would be interesting to try to figure out which components are used most.

Standard
Flex/Flash/Actionscript

tileUI Desktop demo video

Here’s a demo video of tileUI Desktop running as an AIR app. The video shows drag and drop of local files into tileUI, drag and drop photos from iPhoto, using motion detection on a webcam to take pictures, extracting contents of a zip archive and removing a subset of tiles from a stack.

Audio is kind of low, sorry about that.

Standard
Flex/Flash/Actionscript

ImageSnapshot class in Flex 3 SDK

There are a few new graphics classes in the Flex 3 SDK that make it easier to create image snapshots of Flex UI components. The ImageSnapshot class provides some static methods for creating snapshots of components and encoding them as PNG or JPEG images. In addition to the ImageSnapshot class, we also get the PNGEncoder, JPEGEncoder, Base64Encoder, and Base64Decoder, which were all previously in the as3corelib project.

mx.graphics.codec.JPEGEncoder
mx.graphics.codec.PNGEncoder

The JPEGEncoder and PNGEncoder classes were in the as3corelib project prior to Flex 3. They have since been rolled into the main Flex framework. Nice! They’re pretty straightforward, and they’ve been around for awhile in the as3corelib project, so they shouldn’t need much explanation.

mx.graphics.codec.IImageEncoder

The IImageEncoder interface defines an interface for a class that encodes a BitmapData object or the raw bytes of a Bitmap into a new encoded ByteArray. The two classes that implement this interface are PNGEncoder and JPEGEncoder. If you were to write your own image encoders you could implement this interface and then you could pass your custom encoder to ImageSnapshot.captureImage() (read below for more on that).

mx.graphics.ImageSnapshot

The ImageSnapshot class is a new addition to the Flex SDK that simplifies the process of capturing an image from a Flex UI control. This is a task that is often performed, I can think of a bunch of examples right off the top of my head where I’ve had to do this. A live reflection class is one candidate to use this new helper class. I have a feeling a big use of this class is going to be saving image snapshots to the user’s computer in an AIR application. And another use-case that I recently dealt with is converting a Flex UI component to a Base 64 encoded image (see my previous post).

When I needed to get a Base64-encoded string of a given Flex UI component I did something like this:


private function getBase64String(component:UIComponent):String) {
	var bitmapData:BitmapData = new BitmapData(component.width, component.height, true, 0xffffff);
	bitmapData.draw(component);

	var bytes:ByteArray = PNGEncoder.encode(bitmapData);

	var b64encoder:Base64Encoder = new Base64Encoder();
	b64encoder.encodeBytes(bytes);

	var b64String:String = b64encoder.flush();
	
	return b64String;
}

But now we have a much easier way. The ImageSnapshot class has a few static methods that we can use. We get:

captureBitmapData
This is the utility function that returns a BitmapData object. This basically saves us a line of code and simplifies the call. Dimensions are capped at 2880 pixels for each side.

captureImage
This returns an ImageSnapshot object. That doesn’t get us all that much, but there are a few pretty cool things. We can pass captureImage a parameter that tells it how to encode the image. PNGEncoder and JPEGEncoder have been rolled into the framework now, so we can pass in either of those and it will encode the image as a PNG or a JPEG.

Once we get the ImageSnapshot object that the static method returns then we can access the byte data of the encoded image with the data property. Then we could pass the JPEG or PNG encoded image to a server to save the file, or if you’re writing an AIR application you could save the file to the hard drive (or drop it onto the clipboard).

encodeImageAsBase64
This function takes an ImageSnapshot object and encodes it as a Base 64 string. Easy enough.

So to go back to the sample code above, now we can generate a Base 64 encoded string like this:


private function getBase64String(component:UIComponent):String) {
	var snapshot:ImageSnapshot = ImageSnapshot.captureImage(component);
	var b64String:String = ImageSnapshot.encodeImageAsBase64(snapshot);

	return b64String;
}

and if you’re too good for three lines of code:


private function getBase64String(component:UIComponent):String) {
	return ImageSnapshot.encodeImageAsBase64(ImageSnapshot.captureImage(component));
}

Bypassing the 2,880 pixel limit
Flash Player has a limitation of only allowing a single bitmap object to have a max width or height of 2,880 pixels. I’ve never run into this problem, but I guess people with massive monitors can have a problem. The ImageSnapshot class does some fancy footwork in the captureImage method that allows you to generate an encoded JPEG or PNG snapshot that is larger than 2,880 pixels. Basically it creates multiple BitmapData objects and stitches them together to form one final ByteArray. Look at the source code for ImageSnapshot and check out the captureAll method.

This gets around the 2,880 pixel limit, but there’s a 256 meg size limit on a single ByteArray object. From the documentation in the ImageSnapshot class: “This ByteArray is limited to around 256MB so scaled images with an area equivalent to about 8192×8192 will result in out of memory errors.”

So nothing groundbreaking here, but we get to save some boilerplate code that we used to have to write to generate a BitmapData object from a Flex UI object, or to generate the bytes of an encoded JPEG or PNG image. I’m guessing a big reason for Adobe including this in Flex 3 is to make it easier to save JPEG or PNG snapshots of charts in an AIR application.

Standard