Doug’s Blog

Handily dispensing information to .00000001% of the world’s population

Archive for April, 2008

Segway Crash!

Monday, April 28th, 2008

I live near Fisherman’s Wharf in San Francisco, and for those of you who don’t know, “The Wharf” is one of the most visited tourist area anywhere in the world. And as such, it is filled with all sorts of products and services that a tourist would be drawn towards, such as Alcatraz T-Shirts, Golden Gate Bridge snow globes, and, yes, you guessed it — Segway tours.

Every now and then I can spy a group of around 20 tourists in single file segwaying around the streets of San Francisco. On this particular day I watched as five of them got into a big pileup and fell over on top of each other in the middle of an intersection! These things are supposed to be easy to ride, but apparently not too easy.

I couldn’t get my camera out in time to catch the tourists flailing around with their segways on top of them, but here they are trying to drag these things up and out of the way of traffic.

Boom! Crash!

Passing State with a Timer

Monday, April 21st, 2008

Early on in my Flex work I found many cases where I needed the function after a timer event to have some more information. In other words, I really needed to pass state of variables to the next function. You could do this by using global variables, but a cleaner way is to create a subclass of the Timer class and pass along an object.

To do this, you can create this actionscript class in your main mxml directory (or get fancy and name it within subdirectories) as ” ObjTimer.as” and the contents are simply:

// ActionScript file
// ObjTimer is just a timer that can hold an object of variables to pass along
package {
    import flash.utils.Timer;
    public class ObjTimer extends Timer {
        public var obj:Object = new Object;
        public function ObjTimer(delay:Number, repeatCount:int = 0) {
             super(delay, repeatCount);
        }
    }
}

and then you can access it from within your mxml like so for example:

var newTimer: ObjTimer = new ObjTimer(900,1);
newTimer.obj["myvar1"] = "test";
newTimer.obj["firstname"] = "joe";
newTimer.obj["count"] = 10;
newTimer.addEventListener(TimerEvent.TIMER, handleFunction);
newTimer.start();

private function handleFunction(e:Event):void{
    var value:String = e.target.obj["myvar1"];
    var fn:String = e.target.obj["firstname"];
    var count:int = parseInt(e.target.obj["count"]);
}

This example is really quick-n-dirty, you can make it nicer by adding setters and getters in the new class, but for an easy implementation this should get you going.

San Francisco Ready for Olympic Torch Protesters

Wednesday, April 9th, 2008

Everyone knows how much of a ruckus the Olympic Torch is causing this year as it traipses its way across the world. Well here in San Francisco the officials did not want the same silliness that ensued in Paris so they are doing a variety of things, which apparently include helicopters, motorcycle police, police running, police on bicycles, buses full of police that pour out fresh policemen when the running ones get tired, police on horseback, and a big yellow car shaped like a boat.

Just over my house alone I spotted 10 helicopters, I assume a bunch of them are the media. But who knows? They could be packed with SWAT police ready to rappel down and save the torch. Photos below, click for larger versions.

Helicopters protecting the torch Helicoptors protecting the torch

The crowd was excited and peaceful, I did not see anyone charging the torch with a fire extinguisher or any other fire-intimidating device. Which is great, because, really, why protest the torch for crying out loud! The torch didn’t hurt anyone. And certainly the 80 year-old man carrying the torch in one hand, and his cane in the other, doesn’t need anyone yelling at him for the block or two he gets to participate. You want to protest China? Here’s an idea — go to the embassy. Trust me, you don’t want to cross the San Francisco police.

Police protecting the torch Police protecting the torch

Police protecting the torch A yellow boat-car protecting the torch