Travels

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.

Saturday, May 26, 2007

The website went live

It's been a while since my last post so let me catch up on what I've been up to. The biggest thing that happened was that the website I was working on finally went live. I'm glad it did because now I can get back to animating. I'm sort of glad I got to work on the website because I had an excuse to learn PHP and SQL. Now I'm planning on redoing my portfolio site while everything is fresh in my mind. Besides learning server-side scripting, I also learned AJAX (Asynchronous Javascript and XML). If you're not familiar with it, AJAX lets you call functions on your server after a page is loaded, and then update your page without reloading it. I used AJAX to make a live search feature which gives you suggestions for searching while you are typing. My live search is mostly based on Google Suggest.

Since my last post I have also done a couple things to entertain myself. A couple weeks ago I decided that I needed a hat and since I know how to crochet, I decided to make one myself. But, instead of buying a crochet hook, I thought it might be interesting to make one myself. So I went into the woods and found a thick branch and started carving it with a box-cutter knife. It took two evenings and two attempts but, I created a hook. After I sanded it a bit with a nail file I found it was reasonably smooth and worked like a charm. I made a hat with some wool I got from a nearby town. After it was done I decided it looked more like a woman's hat and I gave it to a friend.

Another day I decided to make a Tomato Soup Cake to have a bit of fun. It was a real scavenger hunt when I tried to find all the ingredients I needed. Sugar was especially hard to come by, but I managed to get everything I needed. It was delicious ( tastes like a spice cake).

Thursday, May 3, 2007

In need of more excitement

It looks like our website if finally about to go live. I'm glad because I would rather start working on the animation again. I believe I finally came up with the best way to make all the character keys for the animation. I create layers for the base colors of each key, and then I put them into folders and add layers to my heart's content. The biggest problem making the rabbit was that I didn't label all the layers I made (and I make a good deal of them). So now, once I'm done, I just collapse the contents of each folder and viola! I've got a leg, or ear, etc. ready to be rigged for animation. Another problem I am facing in animating is rigging. I'm very happy to be using Anime Studio Pro, which is the best 2D animation software I've ever used, but using bones to get raster images to deform perfectly is tricky. I may end up cutting the legs up a little so they don't looked so scrunched up when they deform.

I'm always happy to be finished after work but lately, I think I need to find something new to do. I have a book by F. Scott Fitzgerald to read but, I would rather read something else. It may just be time to take a weekend trip to the city to get a better book and buy some music. I need music becuase I didn't have a chance to transfer my collection to my laptop before I left. I'm just glad there is internet radio, though it sounds like there might not be for much longer.

Finally here's a bit of excitement: Yesterday morning I found a scorpion in my yert. Check it out! It was sitting right inside my door, in fact the wood you see in the picture is part of my doorframe. I got it out by picking it up with a stick. It was pretty angry though and started attacking the stick. Luckily, this type of scorpion isn't very poisonous, but I still don't want living in my house.

Here's another picture I took near my house. Though it's less exciting. These two deer live in the woods next to my house so I've seen them a couple times. I think the female is pregnant.

Tuesday, April 24, 2007

Sites and Sights

I'm still working a lot implementing new content on a website. It's not bad, but I realize I like making interactive content much more than web pages. One cool thing I stumbled upon was Google Co-op and Statistics. Google Co-op is a service that let's you and up to 99 of your closest friends create a search engine customized to fit your needs. I've been using it to make a search engine that return results only from our affiliated sites. It works pretty well, though if you add content to your site you need to get Google to update their database before it will show up in your engine. One thing I had to do was to make a hack so the results would show up integrated properly in our web page. Since we use PHP to generate or webpages, it was a little trick. The hack was to send the results to a content page and then call that page from a .php page that was identical to our index.php except the default content loaded was the page containing the search results. Kind of tricky but it looks like it works.

On the less technical side, I took a long walk to the beach on the weekend. The walk takes about an hour and a half. Going there is fine but, coming back is harder because it's all uphill. The beach was breathtaking! It looks like something out of a movie. Other people must think that too because when I went there, everyone on the beach had expensive looking cameras. I thought perhaps it was a photography club out on a picture taking excursion. When I got to the beach my legs were tired and since the water is really cold I decided to wade in it. I learned a while ago on a trip that if you are hiking and then wade in really cold water, it stimulates your circulation and makes your aching legs feel much better. It worked pretty well though I think other people on the beach thought I was crazy to get in the water. I walked around the beach for a while taking pictures, then I climbed up the cliff to take some more. I still wasn't wearing shoes when I climbed the cliff and when I got to the top I found out there were a lot of thorny shrubs. There was a path though, so I stuck to it and tried to minimize my stepping on spiny plants. The view from the cliff was spectacular. When I walked down the cliff I realized there was a path to go up it, and I didn't need to climb like I did coming up. There's always a lot of big bits of seaweed on the beach in this area. I remember coming here years ago and enjoying the sound of hitting the hollow tube seaweed against rocks. The beach was fun and I found two seashells which is a feat considering most west coast beaches I go to don't have any seashells.

The walk back was slow and by the time I got home I had eaten most of my king sized bag of trail mix. The next day I was also surprised that I was not as sore as I thought I would be.