Posts Tagged ‘Flash’

Flash app used to pick winner.

Monday, March 16th, 2009

We recently selected @matthewwithanm as the winner of the Flashpitt suggestion contest, he will receive a complimentary ticket to Flashpitt.

Prior to choosing a winner we had to decide, just that, how we were going to choose the winner. The obvious way would have been to print off everyones names, cut them up, put them in a hat and pick one. Since it is 2009 I figure I can do better than the analog way and I don’t have to risk trees, paper cuts, or loss of fingers (my scissor skills are not the best), so out comes flash and a 20 min code session begins.

I came up with this little gem, where you enter the number of entries you have and a number greater than or equal to 1. The application uses this number to select a random number to decide how many times the Math.random function is ran before the winner is selected.

i.e. say you put 50 in that section the Application grabs a random number between 1 and 50, say 44, then determines that the 44th random number selected will be the winner.

Test it out here.

This movie requires Flash Player 9

I know it’s pretty lame but maybe it will help you in selecting a winner for some drawing your doing. Plus I wanted to post it so when I do another drawing for Flashpitt I can just use this one.

Click here to download the source.

Happy Flashing.

Flash AS3 Navigate to URL.

Tuesday, March 10th, 2009

When making the switch to AS3 there are all kinds of problems we run into, one that I seem to deal with on a daily basis is navigating to a URL.

Back in AS2 it looked like this:

getURL("http://www.joekromer.com", "_self");

AS3 it looks like this:

var URLReq:URLRequest = new URLRequest("http://www.joekromer.com");
try {
	navigateToURL(URLReq, "_self");
} catch (e:Error) {
	trace(e);
}

So I decided I was going to write a quick little class to make my life just a little bit easier. Now after you include my Navigate class all you have to do is call “Navigate.to()”. Of course you need to pass the URL to the function. The function also defaults the target to “_self”, but that can be changed by including whatever target you want.

The code in my class looks like this:

package com.joekromer{
	import flash.net.URLRequest;
	import flash.net.navigateToURL;

	public class Navigate{
		public function Navigate(url:String, target:String) {
			var URLReq:URLRequest = new URLRequest(url);
			try {
				navigateToURL(URLReq, target);
			} catch (e:Error) {
				trace("Oh noes you broke it = " + e);
			}
		}

		public static function to(url:String, target:String = "_self"):Navigate {
			return new Navigate(url, target);
		}
	}
}

With my class you can navigate to a url like this:

import com.joekromer.Navigate;
Navigate.to("http://www.joekromer.com", "_blank");

Download my class.

Happy Flashing.

Flash CS4: Library Item Code Hinting

Tuesday, February 10th, 2009

I seem to always have problems getting the code hinting to appear while developing in the Flash IDE. Until today I miss typed a parenthesis and wham-o now it works.

Example:
I have a Movie Clip in the Library where the “Export for ActionScript” box is checked and the class is called SomeAwesomeClass.

Before, I would reference this clip like this:

var clip:MovieClip = MovieClip(new SomeAwesomeClass());

var clip:MovieClip = MovieClip(new SomeAwesomeClass());

or

var clip:MovieClip = MovieClip(new SomeAwesomeClass());

var clip:MovieClip = MovieClip(new SomeAwesomeClass());

and would never get any sort of code hinting.

Now, I call it like this:

var clip:MovieClip = MovieClip(new (SomeAwesomeClass));

var clip:MovieClip = MovieClip(new (SomeAwesomeClass));

and who’s your uncle, goldenromDOTcom, it works!

Not really sure why it works this way, but it does, Happy coding!