Lunch Chooser

More useful than interesting.


/*
www.foomonger.com
Lunch Chooser
Always trying to figure out where to go for lunch?  Let the Lunch Chooser decide for you.
*/

// list your favorite lunch spots here
var lunchSpots_array:Array = ["Blue Ribbon", "New Asia", "Panera", "Stella's", "Cambridge Common", "Matilda's"];
var shakeInterval:Number;
var shakesCount:Number = 0;

// init the text field
this.createTextField("tf", 0, 0, 0, 190, 100);
this["tf"].selectable = false;
this["tf"].border = true;
var my_fmt:TextFormat = new TextFormat();
my_fmt.align = "center";
this["tf"].setNewTextFormat(my_fmt);
this["tf"].text = "Where should we go for lunch?
Click to find out.";

// set the mouse event
this.onMouseUp = startShake;

// start the shake interval
function startShake():Void {
    clearInterval(shakeInterval);
    shakesCount = 0;
    shakeInterval = setInterval(this, "runShake", 50);
}

// shake the text field
function runShake():Void {
    this["tf"]._x = (this["tf"]._x == 0) ? 6 : 0;
    this["tf"].text = lunchSpots_array[Math.round(Math.random() * (lunchSpots_array.length - 1))];
    updateAfterEvent();
    if (shakesCount++ > 25) {
        stopShake();        
    }
}

// stop the shake interval and find out where you're going to lunch
function stopShake():Void {
    clearInterval(shakeInterval);
    shakesCount = 0;
    this["tf"]._x = 0;
    this["tf"].text = "We're going to " + lunchSpots_array[random(lunchSpots_array.length)] + ".
Don't feel like it?
Click to try again.";
}