Ultra Simple Output Class

Lately I’ve been messing around with Flash on devices and in other “new frontiers”. It’s fun, but sometimes getting debugging working is hit or miss. To address this, I wrote an ultra simple class for tracing to a text field. It’s nothing fancy, but that’s the point – it’s simple (~15 lines of code), tiny (~0.5kb), handy (at least for me), and works well, so I thought I’d share.

To use it, simply drop Out.as into your class directory. Set an output text field when your app starts up:

Out.textField = outFld;

You can also specify a maximum number of characters to retain, so that old traces will be deleted as new ones are added.

Out.maxLength = 1000;

From anywhere in your application you can call Out.trace(value). This will trace the value normally, append it to the end of your text field, and scroll the text field to the end so that the latest trace is always displayed.

Out.trace("hello");
Out.trace("count: ",count); // supports multiple params

Finally, if you want to do something more custom, you can override Out.handler to use your own function.

function log(...rest:Array):Boolean {
  trace("logging: "+rest.join(","));
  // ... etc.
  // only write to text field if first param (ex. priority) is > 1:
  return rest[0] > 1; // returning false prevents it being written to Out.textField.
}
Out.handler = log;

You can download the Out class here. It is licensed under the MIT license.

Androideroids

There’s a lot of buzz around multi-screen experiences lately, where an application or game is available to you on multiple devices (ex. web, PC, mobile, TV, etc). Recently I’ve been fascinated by the idea of using these “multiple screens” together to create a single experience.

The first result was my Nexus One Gas Pedal which I posted last week. Following that, I wanted to do something that was more accessible, and allowed for more players, which led to the concept for Androideroids.

Androideroids is a prototype multiplayer asteroids game in which each player uses an Android phone as their game controller. Player’s can see a top down view of the game on the main screen (which could be a PC, TV, or projected in a public space), and a first person view with their health and score on their phone. The top down view is great for navigating, and first person view comes in handy for aiming during dogfights. Player specific sounds are played on the phone, whereas general sounds are played on the host.

This has lead to the development of what I feel is a strong framework for creating public installations and experiences that will allow smart phone users (on multiple platforms) to connect in an adhoc fashion.

When players launch the generic LANPad application on their phone, it finds and connects to the game host. The host sends the client a “surface” SWF which defines how the game will look and act on the phone.

The surface SWF sends messages to the host indicating UI input, the host interprets these, runs game logic, and sends back a message updating the game state on the phone.

Here’s a rough video on the project:

Continue reading →

AIR for Android Wireless Slot Car Gas Pedal

Recently I’ve been trying to carve out more time to play with technology – something I’d been neglecting sorely, despite constant admonitions (1, 2) to others to always make time to play.

One of the first results of this is a library for creating peer to peer LAN connections between AIR applications, with a strong focus on mobile to desktop applications. I’ll go into more depth about the LAN library in a future post, but for now I wanted to share something I built on top of it… the Nexus One Wireless Slot Car Gas Pedal.

Check it out in the following video:

Continue reading →

Quick Way to Set Props on a New Instance

I recently posted a feature request for AS3 asking for property initialization for instance construction. If you want details, check out bug #ASL-69.

In one of the comments, I referenced an existing way to quickly set properties on a new typed object, and thought it might be worth sharing. It’s super simple, but might prove useful.

Simply put the following code into a “setProps.as” file in your class path:

package {
public function setProps(o:Object, props:Object):* {
for (var n:String in props) {
o[n] = props[n];
}
return o;
}
}

Now, from anywhere in your code, you can quickly set multiple properties on an object. This can be handy when creating new instances. For example:

addChild( setProps( new Sprite(), {x:200, y:200, alpha:0.5, name:"bob"} ) );

This obviously isn’t type-safe, and it won’t provide compile time errors if you get a property name wrong. For small projects with short timelines, or just playing around it can make it easier to hack things together, but I don’t recommend it for larger or more formal projects.

The goal of my feature request was to enable similar ease of use, but with type safety, compile time errors, and full IDE support. Feel free to vote for it here.

BitmapSlice9: Scale9 for Bitmaps in Flash Pro

BitmapSlice9 is a command for Flash Pro that preps bitmaps for use with Scale9. Among other things, this makes it easy to use bitmap skins for controls, which is quite common for games and mobile apps.

In short, it slices your target bitmap into rectangles with custom bitmap fills according to the applied Scale9 grid. It also preserves your original bitmap in a guide layer (to keep it from compiling into the SWF) to make it easy to adjust and reapply the command.

Here’s a quick video showing how it works. It’s the first tutorial video I’ve ever done, and the audio is really terrible – I obviously need to get a decent microphone.

Continue reading →

Return of the Blue Lego

As some people have noticed, Apple has eliminated the blue lego icon that indicates a missing plugin on the iPad. I believe that this is a not so subtle way of shifting users from believing that the iPad browser is lacking something, to believing that the site they are viewing is broken.

In response to this, I’ve created the blueLego edition of SWFObject 2.2. It works exactly the same as regular SWFObject, except it will display the blue lego icon, with a link to Adobe’s get Flash Player page on iPhone, iPod, and iPad.

As of April 13, this page correctly displays content explaining to iPad users why Flash is unavailable on their device. This is the same content shown on the iPhone, which is described here. You’re obviously free to modify the iDevice alternate content or the code itself to suit your own needs.

It is released under the MIT license, and you can download it by clicking here. Whether it is useful for production or not, I leave to you. It was created more as a statement than anything.

The blueLego art was created from scratch and I’ve included the source FLA so you can modify it as you like.

It looks like this in use:

You can test it by pointing your iDevice browser to this url:

http://gskinner.com/playpen/bluelego/

Thanks to Rob Hall and others for helping spark the idea.


Edit: Copying my comment from below here, to clarify the purpose of this post:

This post was *not* a Flash pro/con, or Flash vs HTML5 statement.

Apple made a conscious decision to move from fairly and correctly showing users that they were unable to display a certain type of content (whether you like that content / technology or not), to making it look like the site itself is broken. It places the apparent blame not on Adobe or Apple, but on content providers. Regardless of your position on Flash or plugins, this is wrong, and it’s a dirty play by Apple.

This post, and the blueLego SWFObject library were intended as a light way to point out the issue and to help rectify it for site owners by letting them accurately convey why their content does not work on an iPad. It was not intended as some weak form of “revenge” at Apple.

Colorgasm Music Visualizer

While exploring the flash.sampler API this morning, I whipped together a quick demo to test its output when rapidly creating / deleting objects.

The demo turned out kind of cool in it’s own right, so I thought I’d post it. Nothing incredible, but you’ve gotta love what you can accidentally create in a couple hours and 1.8kb in Flash.

Note that I’m too lazy to add a preloader, so nothing will happen until it loads the 5.4MB music file.

One day maybe I’ll play with this some more, tie in proper spectrum analysis, a preloader, etc. *shrug* The Hype framework would probably work great as a starting point for that.

Continue reading →