Posts Tagged ‘Flash’

Create an Array of Random Numbers, Without Reusing Numbers

Monday, December 10th, 2007

I recently had the situation where I had to create an array of 25 random numbers from 0-24, but no number could be repeated in the array. So after a little bit of racking my brain I came up with this.

//create an array to hold the numbers
var numArray:Array = new Array(25);

// create an array to hold the used numbers
var usedNumArray:Array = new Array(25);

for (var i:int = 0; i <= 24; i++){
	pickNum(i);
}

// run fuctions to get a random number and put in it the array
function pickNum(i:Number){
	var num:Number;
	do{
		//set num to a random number between 0-24
		num = getRandNum();
		//set the numArray[i] to the random number
		numArray[i] = num;
		//make sure the number is a new number
	}while(usedNumArray[num]);
	//if its a new number set the usedNumArray[num] to true
	usedNumArray[num]=true;
	//trace it back to make sure it works
	if(i == 24){
	trace(numArray)
	}
}

// get random number
function getRandNum():Number{
	return Math.floor(Math.random()*25);
}

I don't know if its the best way to handle it but it works. If there is a better way please let me know.

Went to the "From the Ground Up Tour" with Colin Moock

Wednesday, December 5th, 2007

I attended in Chicago and had a really freakin’ good time, learning a bunch about AS 3.0. On a good note it was very class heavy which is something I have been wanting to learn. Now a few days later I’ve been working with the Public Beta of Flex 3, teaching myself how to use classes. Hopefully I will have some examples to post, soon.

Flash CS3 Simulate Download Bug

Friday, November 2nd, 2007

I noticed a bug(I think) when I Simulate Download on a few Flash files today.

So I test the movie and every thing shows up totally cool as below:

Then I go to Simulate Download and I end up losing some of my images, what’s the deal. See below:

Any way not a huge deal cause it all works good outside of the Flash IDE, but still kind of annoying.

*sorry about the blurriness once the pages go live I’ll clear them up.