Travels

Thursday, January 10, 2008

I ♥ caller

Since I posted about the wonderfulness of the Delegate class for AS2 I've learned a little bit more useful info I'd like to pass on. As you may remember, the Delegate class is very useful for managing the scope of your code. The biggest problem I still ran into though was passing and accessing variables from my the custom handlers I made with the Delegate class. Thankfully , there is an easy way to pass variables. Simply add it as an attribute to the event handler.
E.G.

//import the Delegate class
import mx.utils.Delegate;

//add a variable to pass to your handler
something.onPress = Delegate.create(this, someHandler);
something.onPress.myVariable = "pass me";

//now to access that variable use caller
function someHandler(){
var passedVar= arguments.caller.myVariable;
trace(passedVar);
}

Voila! Now you can enjoy the satisfaction of passing variables to your custom handlers.

Wednesday, November 21, 2007

Chumby

Recently I came upon a device called the Chumby. If you haven't heard of it, the Chumby a compact computer that displays information from the web via wireless. It has a touchscreen, 2 usb 2.0 ports, an accelerometer and a squeeze sensor. Best of all, it is designed to be easily hacked both for software and hardware. Anyone can make widgets for the Chumby using Flash Lite 3.0 as well as a variety of other languages (Chumby is Linux based). The screen is 320*240 and the recommended framerate is 12fps. Looking over Chumby.com's wiki, it looks like things are very well documented with example files to download and try out.

I think the idea of the Chumby is very cool and I'm excited to try it out for myself. At $179.95 it is a little pricey but, it is exactly what could integrate the internetin new ways to affect our daily lives (especially with web 2.0 technology like RSS). Imagine having a Chumby in your kitchen, you could get recipes off the intenet, watch online video, listen to internet radio, check the weather and traffic while you have breakfast, and read the daily news. I myself would be interested in a Skype widget so I could use it like a phone.

There's a bunch of cool widgets and features already available for the Chumby at the official website: www.chumby.com.
So check it out for yourself.

Monday, November 12, 2007

Making Flash games for the Wii

Recently I was shopping at Circuit City and found something interesting. It was a program called my Wii Manager. This software that allows you to download, edit, and share your Mii characters; so far you might not be impressed. But what the software actually is, is much different. It includes a programmable input emulator with an archive of programs for using the Wiimote on the computer. So it allows you to relatively easily connect your Wiimote to your computer and receive and use its serial input to control your mouse. It runs without a UV sensor so all moving is done by tilting the Wiimote; the cool bit is that it can detect tilt, thrust, and some other movement as well as make the Wiimote vibrate and light up its LEDs.


The real reason why I bought the software was that it came with a Bluetooth dongle and the whole thing cost about $20. When I was searching for a single Bluetooth dongle, the prices were usually closer to $30. So with this software you not only get the dongle but the emulator with program archive and some documentation. For my money, this is a pretty good deal. The main thing that had been keeping me from playing with making Flash games for the Wii, was that it was too much work to figure out how to set everything up and get it working reliably before I could get to making games. So if you're curious about making Flash games for the Wii, check out my Wii Manager.

After setting everything up (took about half an hour of reading and fiddling about) I played with a couple of old Flash toys I made. The results were pretty encouraging. A while ago I started working on a gesture class that maps various types of mouse movement to specific gestures. The goal was to add a greater sense of immersion to gameplay through more familiar and intuitive interactions. When I tried playing with the old toys I made using this class, they mapped wonderfully to the Wiimote and the interaction felt nice. So I've decided to slowly make a bunch of minigames using the class which later on I'll put together in one larger game. This will take a while though since I'm still in the middle of redesigning my website. Hopefully I'll be able to squeeze in a minigame or two along the way. Once I've finished a couple of minigames, I'll post the code and the games at my website.

Thursday, October 25, 2007

The Delegate Class: Brother where have you been?

Eureka! I've had a specific problem when writing AS2 classes for some while now. Namely, whenever I use code to make an interactive element (Let's say a movie clip that bounces away when you click on it), I have to nest the event handler's method. The problem is that this changes the scope and so the handler method can't access my classes base methods. The way I used to fix this was by making the methods I want to access Static, and accessible by anything in my class. The problem with this is that if I make a method static I have to make its variables static, and that can create a domino effect of making things static just to solve the original problem. This is pretty wordy so I'll post code that is easier to follow. Here's the old way I did things:

class SomeClass {
//constructor
public function SomeClass(someMC) {
//initialize object
initialize(someMC);
}
//this is static so the onPress method can access it
private static function doSomething() {
trace("Ok, I'm doing something");
}
private function initialize(someMC) {
trace(someMC);
//define what it needs to do when it loads
someMC.onPress = function(){
doSomething();
}
}
}

This is a very simple version of the problem. In reality the method my handler calls would probably be called by other methods and use variables that all would need to be made static. I knew this was not a good way to do things but until now I didn't know what else I could do.

Thanks to the Delegate class though, I'm able to specify the scope and therefore access the methods at my class' base level. Here's the same code as above but made with the delegate class:

//import the Delegate class
import mx.utils.Delegate;
class SomeClass{
//constructor
public function SomeClass(someMC) {
//initialize object
initialize(someMC);
}
private function pressHandler() {
trace("You pressed it.");
}
private function initialize(someMC) {
//define what it needs to do when it loads
someMC.onPress = Delegate.create(this, pressHandler);
}
}

Now there is no need for static so things are much easier when I need to tweak things later on.
While I was researching how to solve this problem I found other possible solutions but this was the one I understood best and was able to easily implement.

You can read all about the Delegate Class here: http://www.actionscript.org/resources/articles/205/1/The-Delegate-Class/Page1.html

This is all great to know but this problem has been resolved in Actionscript 3 thanks to its addEventListener method. Still if you're using on Flash Lite or like me your work doesn't want you to use AS3 until the Flash PLayer 9 adoption rate is higher you may find this very useful.

Good luck using the Delegate Class, and if you have other solutions I'd love to see what you have come up with.

Tuesday, October 23, 2007

Tip for Text in Flash

I was working my way through the hefty, 900+ page book Essential Actionscript 3.0 with the hopes of finishing it by the month's end when I learned something new. It has happened to me before that I wanted to use some dynamic text as part of something that rotated, skewed, or changed transparency. This never seemed to work so I always resorted to breaking the letters apart into graphics and abandoning the idea of dynamic text. Today, as I was reading page 705, I learned that dynamic text can be used in all these wonderful effects as long as you embed it. I did some tests and it is indeed true. Just make sure that you embedded all the symbols necessary, otherwise your text might be missing things when you render the swf.

You can see this in action in the new widget I've made for this blog, my Flickr Image viewer. This widget gets the 20 most recent pictures I've uploaded to my Flickr account and makes a cross-fading slide show with captions. As you can see I have embedded the font I use so the text as well as the images fade in and out. I made this widget with the help of the SWX technology created by Aral Balkan which allows Flash to easily access Flickr API (and others) easily without writing any server-side code.

Wednesday, October 17, 2007

Back in a strange new place

It's been a while but I've decided to keep this blog going. I've started working at a new job since my last post and moved to a new city. I'm very happy to say that my new job sent me to FlashForward 2007 in Boston, and I had a great time! There was so much there that inspired me that once I got home I felt overstimulated. There was too much for one post, so I'll be spreading things out over several posts.

Let me tell you about animation. The best things I learned for animation probably came from Chris Georgenes' talk. He went over some animation tricks and showed us some nice animation clips. I found the tips on lipsynching especially useful. Here's the gist:

1. Make a mouth graphic symbol (it must be a graphic).
2. In the symbol draw all the mouth shapes you want to use. You can use onion skinning to help you position the mouths.
3. Go back to the main timeline and add a keyframe, click on the mouth symbol, make sure single frame swapping is selected, and then enter the number of the frame with the mouth shape you want.
4. Continue as desired and that's it. You've learned single frame swapping.

You can watch a video tutorial of this as well as several other useful Flash animation tutorials by Hayk Manukyan at his blog: http://moolt.blogspot.com/2007_09_01_archive.html


I like this feature but it can get confusing remembering the frame numbers if you have many shapes. Once things ease up at work I think I will make a Flash extension for lipsynching that uses this feature but adds visuals so there will be no need to memorize the shapes.

Wednesday, May 30, 2007

Some pictures I took

I just wanted to share some nice pictures I took. The one below is a pregnant doe that I managed to get close to.


This next picture is of of a moth that was resting on the window of my office.


The area where I live has many redwood trees. In case you don't know, redwood trees tend to grow in circles around a "father tree". This is a picture of the remains of the "grandfather tree" from which all the redwoods in my area were grown. The trunk is about 21 feet around and is hollow because it was burned by fire several years ago, possibly because it was struck by lightning.