![]() |
Welcome To Swish-Designs.co.uk Have a Nice Friday
English National Lottery Number Generator.
Learn how to create a random number generator. ideal for generating lottery numbers.
Instructions
Click on the generate button to randomly generate a lottery ball number
for the English National Lottery.
First Of All
You can see this Generator in action Here using 6 balls.
The Movie: for the purpose of this tutorial i have used a canvas size of 113 x 137 pixels with a frame rate of 25 fps and background colour of white #FFFFFF.
Ball category's: Numbers 1 - 10 = White ball
Numbers 11 - 19 = Blue Ball
Numbers 20 - 29 = Pink Ball
Numbers 30 - 39 = Green Ball
Numbers 40 - 49 = Yellow Ball
Step.1
Using the Elipse tool and whilst holding down the Shift key on the keyboard drag out a circle on your canvas similar to the one in fig.1 below. and name is Mask.
Fig.1
Step.2
Right click on the mask shape and click on copy and then paste in place, rename this shape as white and give the shape a fill colour of white #FFFFFF , then press Ctrl+Shift+V to paste in place again, rename the shape to blue and give the shape a fill colour of blue #0099FF, again press Ctrl+Shift+V to paste in place again, rename the shape to green and give the shape a green fill colour #00FF00,
click Ctrl+Shift+V again to paste in place and rename the shape to Yellow and give the shape a fill colour of yellow #FFFF00, now press Ctrl+Shift+V to paste in place again rename the shape to pink and give the shape a fill colour of pink #FF00FF, you should now have something looking like fig.2 below.
Fig.2
as pink being the last colour to be pasted in place. in your outline panel you should now have the following shapes. Pink, Yellow, Green, Blue, White and Mask.
Step.3
Now you have the solid shape of a ball we need to give a little definition, so using the Rectangle tool drag out a rectangle along the bottom of the pink shape and give it a Linear Gradient colour fill of Black to fransparent white duplicate this shape using the copy and paste in place technique. and place them as in fig.3 below. name both the shapes as shading.
Fig.3
Step.4
Now you have the Shaing in place you just need to create where the light hits the ball to make it look like 3D, so using the elipse tool drag out a smallish circle name it light and give a Linear Gradient colour fill of solid white to transparent white. and place as seen in fig.4 below.
Fig.4
Step.5
Using the Text tool select the Arial font size 22 and click on Bold and place it in the middle of the ball and make the text Dynamic typing the numbers 00, name this as Lucky_Number and give it a variable name of myText1 now select all the objects on the stage by pressing Ctrl+A and group them all as a sprite naming the sprite as ball1 and check the box that says use bottom object as mask, you should have something looking like fig.5 below.
Fig.5 Now if you click on the play button above the timeline you should have something looking like fig.5a below.
Fig.5athis is because it is using the first shape you created the black cirle that you name mask, and when you create the sprite you checked the box that said use bottom object as mask. so everything outside the masked shape does not show up in your movie. just what is inside the masked shape.
so by now you should just have a ball that resembles a 3D ball.
if at this stage you do not have something that looks like Fig.5a above take a look at Fig.5b below to see the order of objects in the outline panel.
Step.6
Now to add some code to get the lucky number text box to create randomly generated numbers everytime. so select the ball1 sprite by clicking on it in the outline panel, then click on the script tab and make sure you are in Expert mode then copy and paste the following code.myRange = 49;
myNumber = Math.round(Math.Random()*myRange);
myText1 = myNumber;
}
onLoad () {
changeNumber();
}
Explanation of the above:
the function is to change out lucky number, my range is how many numbers to randomise from
in our case the lottery has 49 numbers, myNumber is the final number that is going to be generated from the range number of 49, MyText1 just finaly shows the number which has been randomly generated from the possible 49 numbers.
Step.7
Now add the following code underneath the existing code .if (myText1==0) {
changeNumber();
} else if (myText1==1) {
myText1="01";
} else if (myText1==2) {
myText1="02";
} else if (myText1==3) {
myText1="03";
} else if (myText1==4) {
myText1="04";
} else if (myText1==5) {
myText1="05";
} else if (myText1==6) {
myText1="06";
} else if (myText1==7) {
myText1="07";
} else if (myText1==8) {
myText1="08";
} else if (myText1==9) {
myText1="09";
}
}
Explanation of the above:
The above code basicaly turns single numbers into double numbers so 1 would translate to 01 in the display and 2 would translate to 02 in the display up to 9 to 09 myText1 is where the numbers are displayed.
Step.8
Now add the following underneath the existing code.stop();
}
onFrame (2) {
setLabel("white");
}
onFrame (3) {
stop();
}
onFrame (4) {
setLabel("blue");
}
onFrame (5) {
stop();
}
onFrame (6) {
setLabel("pink");
}
onFrame (7) {
stop();
}
onFrame (8) {
setLabel("green");
}
onFrame (9) {
stop();
}
onFrame (10) {
setLabel("yellow");
}
onFrame (11) {
stop();
}
Explanation of the above:
Again this is prety straight forward, it justs sets the labels for the different colour balls that will be displayed, labels are simpler to use rather that telling the code later to goto&play frame bla bla, you can just tell it to goto&play the coresponding color as you will see in the next part.
Step.9
now add the following code underneath the existing code.if (myText1<=10) {
gotoAndPlay("white");
} else if (myText1==11) {
gotoAndPlay("blue");
} else if (myText1==12) {
gotoAndPlay("blue");
} else if (myText1==13) {
gotoAndPlay("blue");
} else if (myText1==14) {
gotoAndPlay("blue");
} else if (myText1==15) {
gotoAndPlay("blue");
} else if (myText1==16) {
gotoAndPlay("blue");
} else if (myText1==17) {
gotoAndPlay("blue");
} else if (myText1==18) {
gotoAndPlay("blue");
} else if (myText1==19) {
gotoAndPlay("blue");
} else if (myText1==20) {
gotoAndPlay("pink");
} else if (myText1==21) {
gotoAndPlay("pink");
} else if (myText1==22) {
gotoAndPlay("pink");
} else if (myText1==23) {
gotoAndPlay("pink");
} else if (myText1==24) {
gotoAndPlay("pink");
} else if (myText1==25) {
gotoAndPlay("pink");
} else if (myText1==26) {
gotoAndPlay("pink");
} else if (myText1==27) {
gotoAndPlay("pink");
} else if (myText1==28) {
gotoAndPlay("pink");
} else if (myText1==29) {
gotoAndPlay("pink");
and finaly add the rest underneath the existing code.
gotoAndPlay("green");
} else if (myText1==31) {
gotoAndPlay("green");
} else if (myText1==32) {
gotoAndPlay("green");
} else if (myText1==33) {
gotoAndPlay("green");
} else if (myText1==34) {
gotoAndPlay("green");
} else if (myText1==35) {
gotoAndPlay("green");
} else if (myText1==36) {
gotoAndPlay("green");
} else if (myText1==37) {
gotoAndPlay("green");
} else if (myText1==38) {
gotoAndPlay("green");
} else if (myText1==39) {
gotoAndPlay("green");
} else if (myText1==40) {
gotoAndPlay("yellow");
} else if (myText1==41) {
gotoAndPlay("yellow");
} else if (myText1==42) {
gotoAndPlay("yellow");
} else if (myText1==43) {
gotoAndPlay("yellow");
} else if (myText1==44) {
gotoAndPlay("yellow");
} else if (myText1==45) {
gotoAndPlay("yellow");
} else if (myText1==46) {
gotoAndPlay("yellow");
} else if (myText1==47) {
gotoAndPlay("yellow");
} else if (myText1==48) {
gotoAndPlay("yellow");
} else if (myText1==49) {
gotoAndPlay("yellow");
}
}
Explanation of the above:
the above code simply checks what number has been generated then points it towards, the corect color ball for that number.
all their is to do now is set the following place and remove symbols in the same place as fig.6 below
this will determain what colour balls show under the colour tabs.
At this stage if you press Ctrl+Alt+T to test in browser, your ball should generate a new number each time you refresh the page.
Step.10
If you want to add a button to generate a new number instead of having to refresh the page, simply create a button of your choice and add the following code.ball1.changeNumber();
}
Ok thats it for the lotery number generator tutorial, i hope this has been usefull for you in some way,
if so please consider making a donation to help keep this site running, enabling me to keep bringing more tutorials to this website.
Regards,
Craig.


