View Full Version : Slot Machine Scroller
adamfilip
07-28-2005, 04:13 PM
I need to make a dynamic Scrolling Slot Machine Wheel
I need it to load in 10 small external Jpegs scroll vertically seamlessly quickly then come to an abrupt halt on a specific image that is passed from a variable (1-10)
anyone know how to acomplish this.
Please help :)
Ricod
07-28-2005, 07:36 PM
What part do you already know ?
- Do you know how to load in jpegs ?
- Do you know about getting data from a variable ?
- Do you know how to set properties of movieclips ?
- Do you know how to loop ?
adamfilip
07-28-2005, 07:40 PM
What part do you already know ?
- Do you know how to load in jpegs ? yes
- Do you know about getting data from a variable ? yes
- Do you know how to set properties of movieclips ? yes
- Do you know how to loop ? yes (i believe)
Ricod
07-28-2005, 08:23 PM
Well, that's all there is to it actually. Almost.
Do you know how to make a mask ?
Are the images sequenced or random ? Are they all the same size ?
There are more ways to go here, but did you try a basic setup first ?
So, you load the jpegs, preverably each in it's own mc. They're labeled accordingly. You then move them down and every time an image enters the visible area you place the next one on top.
To stop it at a certain image depending on a variable, you should have the mc labeled accordingly (for instance, image1, image2 etc. You get the drill).
Then check to see if this image is in the visible part or about to get there. Let's say your visible area is from x:50,y:50 till x:400,y:300 and each image is 50 by 50 pixels.
The center of the visible area (y:125) is where you want the targeted image to stop. So, you check the _ property of the targeted image and if it's at or near the center (take into account that it's moving a certain amount of pixels per interval), you stop the scrolling.
I suggest you use setInterval() for that, since you can remove the interval with clearInterval(). Are you familair with these methods ? If not, take a look at the helpfile, there's an example describing how to set and remove intervals there.
adamfilip
07-28-2005, 08:53 PM
Ive attached a simple file
it contains the fla i have now.
on screen are 6 image placeholder movieclips
I have 10 jpeg images in an images folder
i put them into a mask to block out the background
im not very good at action script
the images need to be in sequence
because eventually im going to have 4 seperate tumblers running togethe to form what looks like an actual slot machine
Ricod
07-29-2005, 01:00 AM
Okay, take a step back for a second.
The onClipEvent(enterFrame) method is used to have something performed every time that mc goes to a frame. Loading in a graphic is something you only need to do once for every graphic. Besides, depending on the size of the graphic and the bandwith of the user, it'll take more than 1/12th of a second (ot less if your fps is higher than 12 fps).
A statement needs to be ended with a semicolon ";".
I could write out the code to get this slot working, but you need to learn the syntax of Actionscript, or else the next time you want to do something like this again, but slightly different, you're going to be right back here.
I suggest you take a look at the helpfile for the following entries :
"Actionscript Basics"
"Terminology"
The "Syntax" section
You're probably familair with the data types, but if not, take a quick look at them.
Understanding variables and movieclips are the ones you want to familarize yourself with first. We also have a few tutorials in the tutorial section you may want to look at.
The Actionscript Reference section has help files on every method you need, so at least check out :
else and else if
for
function
if
loadMovie
MovieClip Class
MovieClip.createEmptyMovieClip()
MovieClip.duplicateMovieClip()
MovieClip.getBytesLoaded()
MovieClip.getBytesTotal()
MovieClip.getNextHighestDepth()
MovieClip.loadMovie()
MovieClip._y
Let us know when something isn't clear. I think that when you know what each of those methods do, you can think of how to use them to get your slot machine set up. My previous post contains some pointers on the logic.
adamfilip
07-29-2005, 03:45 PM
alright ive been trying
im all confused
I can get it to load the movieclip with the jpeg dynamically
but i cant get it to move them
I first need it to load 5 or 6 prizeimages. then to begin scrolling
after they are loaded
runMachine()
var tumbler_array:Array = new Array();
var numTumblers:Number = 10;
//************************************************** ******
//*** FUNCTIONS ******************************************
//************************************************** ******
//*** Run Machine
function runMachine(){
this.onEnterFrame = function(){
createTumbler1()
runTumbler1()
}
}
//*** Create and Run Tumbler ******************************************
function createTumbler1(){
for (var i=0; i< numTumblers; ++i){
var currentFileName = ("images/" + i + ".jpg");
var prizeName = ("prize" + i +"_mc")
trace(currentFileName);
tumbler_array[i] = tumbler1_mc.createEmptyMovieClip(prizeName, ++depth)
trace (prizeName)
this.loadMovie(currentFileName);
runTumbler(prizeName);
//resetPrize(i);
}
}
//*** Reset Prize ******************************************
function resetPrize(j:Number){
tumbler_array[j]._y = 150;
tumbler_array[j]._x = 150;
}
//*** run Tumbler ******************************************
function runTumbler(k:MovieClip){
trace (tumbler1_mc.k._y)
tumbler1_mc.k._y += 1;
if (tumbler1_mc.k._y > 447){
tumbler1_mc.k._y = 0;
} else {
tumbler1_mc.k._y += 1;
}
}
//*** remove prize *******************************************
Ricod
07-30-2005, 12:06 AM
I just took a quick peek at your code.
You can't move them because you're not putting the paths to the dynamically added mcs, but the constructor.
tumbler_array[i] = tumbler1_mc[this.currentFileName];
The resetPrize function sets each image at those coordinates. I don't think that's what you want.
The runMachine() function is also a bit unefficient.
Why the onEnterFrame here ? I think you want that added to the tumbler1_mc (and later the other tumblers I guess)
And I don't think you want a new tumbler being created every frame (12 tumblers per second if you use the standard 12 fps).
vBulletin® v3.7.1, Copyright ©2000-2009, Jelsoft Enterprises Ltd.