Monday, June 02, 2008

Happy June

Things are busy as usual and that means not posting. That's not to say I'm not doing anything and just to prove it...

I ran into a problem in a recent project where I had a series of buttons and I wanted to one to be active right off the bat. ie, like a gallery where the first image is the triggered from the first thumbnail.

There are two ways I found;

1. When your button isn't actually sending any information along with it you can change your callback function to accept a null parameter.

ex.
button.addEventListener(MouseEvent.CLICK, onClick);

private function onClick(mevt:MouseEvent=null):void
{
//do whatever here
}

now I can just call the onClick function like any regular ol' function

onClick();

However, if you want to actually click the button because you need to know something that button has;

//using the same code as above

button.dispatchEvent(new MouseEvent(MouseEvent.CLICK));

TADA!

Now tell me I haven't been doing anything.

Labels: , ,

Monday, April 28, 2008

Bit-101's Three Useful Methods

Keith Peters posted on his blog last week three useful methods.

I've added a couple of extra methods that I'm finding I use more often than not and might as well shove into this class. Shove is an inelegant word, but I'm an inelegant guy.

//thanks, Keith.

public static function distanceCalculation(x1:Number, y1:Number, x2:Number, y2:Number):Number
{
var dx:Number = x1 - x2;
var dy:Number = y1 - y2;
return Math.sqrt(dx * dx + dy * dy);
}

//I mixed something up here. Fixed the randomRange value return. Thanks again, Keith.

public static function randomRange(start:Number, end:Number):Number
{
return Math.floor(start + Math.random() * (end - start));
}
It's fair to note that I didn't create these methods. They were found at various times in various locations. I just keep misplacing them and looking for them again. Good to know that it's last time I'll do it.

It's nice to be spurred on to centralizing this stuff. Thanks, Keith!

Labels: ,

Thursday, February 07, 2008

BulkLoader

This nifty library gives you the power (that's right, I said "power") to load multiple items easily.

Very nice.

Labels: ,