Jigsaw
Gary great book. I'm new to AS3 and fairly new to programming. I find your book much easier to read than some of the dry manuals off the Adobe site or the Moock book. If those books hadn't bored me to death I might have been able to figure out the following problem.
I'm trying to modify the jigsaw puzzle in your book so that it will randomly select from ten jpegs. I first thought I should generate a random number between 0-9. I inserted this code...
// random number
var pictureSelector:Number = Math.random()*10;
trace(pictureSelector);
I can't even get the trace to spit out the number. After that I tried to modify the code with this...
// load the bitmap
loadBitmap("jigsawimage"+pictureSelector+".jpg");
It didn't work. I really didn't think it would be that easy, so I changed the "load the bitmap" section to this...
public function startJigsawPuzzle() {
if (pictureSelector == 0) {
loadBitmap("jigsawimage0.jpg");
} else if (pictureSelector == 1) {
loadBitmap("jigsawimage1.jpg");
} else if (pictureSelector == 2) {
loadBitmap("jigsawimage2.jpg");
} else if (pictureSelector == 3) {
loadBitmap("jigsawimage3.jpg");
} else if (pictureSelector == 4) {
loadBitmap("jigsawimage4.jpg");
} else if (pictureSelector == 5) {
loadBitmap("jigsawimage5.jpg");
} else if (pictureSelector == 6) {
loadBitmap("jigsawimage6.jpg");
} else if (pictureSelector == 7) {
loadBitmap("jigsawimage7.jpg");
} else if (pictureSelector == 8) {
loadBitmap("jigsawimage8.jpg");
} else if (pictureSelector == 9) {
loadBitmap("jigsawimage9.jpg");
}
That didn't work. I also thought of possibly using a "switch" instead of the "if else if". I'm at a loss for how to do this. If Gary or anyone else knows the answer please help out a novice and drop a few hints. It would be greatly appreciated. Otherwise I'll keep hitting the books and let you guys know if I find the answer.
Colonel
Copyright Gary Rosenzweig
