is there anyway that i can move to some frame in actionscript based on a random number from a dice? - actionscript-3

here's the thing, i am actually new to actionscript and currently developing a a game in flash. the game is snakes and ladders. i have problems with regards to how to move the player avatar to the boxes of the game board. here's what i did. i made 100 frames, and with each frame is where the position of the avatar. (for example, frame 2 shows that the avatar is in box 2, etc).only thing is how do i make the frame move depending on a random number given by the dice.?
for example if i was originally in frame 2, and the dice gave a random number of 5, how do i get to frame 7? like playing the frames 3 - 6 and stopping at frame 7?

To move to a specified frame, invoke gotoAndStop() with a frame number as parameter. Of course, it can be calculated, and you can refer to movieclip's current frame via currentFrame property.
The manual

Related

How do I iterate through a number of sprites frame by frame when i move my character to the right?

I have never made a html5 game before and i made some sprites for a simple crossing game. I would like to make my character use a array of four different sprite frames when moving to the right and then cycle through till the last one until i stop moving, where by it then reverses the loop and cycles back to the original sprite frame.
I would like to have that function for both left and right movement. I want the same function but with sprites facing the opposite way when moving left.
If my character collides with a enemy sprite i want the fifth sprite frame for each direction to trigger and stay the sprite when game over. It is a game over sprite which two exist, one for each direction the player was moving when they collided with the enemy. total sprites for player is 10, five for each direction of which four are used each way unless a collision happens where the fifth of the particular direction is triggered.
The enemy sprites consist of only two frames that cycle over and over infinitly until the game is over.
The last frame is for the goal which is a static frame which does not change.
How can I make this work?
I am new so i have no idea if or how exactly I should build a array to cycle through the images for each direction or if i should do some for loop or if loop or for eachloop?
To get a cycling index from an incrementing number, use the modulo operator:
sprite_index = step_number % 4
then sprite_index will be 0,1,2,3,0,1,2,3,0,1,2,3,... as step_number increases like 0,1,2,3,4,5,6,7,8,9,10,11...
Don't use a loop because you will already have a loop for moving the characters and so on anyway. An extra loop inside that will stop the main loop while it runs.

Accessing animation of nested symbols using AS3 in Flash CS4

It's for my college project again.
I am making a Zombie shoot-em-up game. I created a Zombi symbol with the default Zombie sprite. Inside the symbol I placed three more sprites that are ZombiAttack, ZombiIdle, and ZombiMove, in the frames 1, 15 and 20 respectively. I further converted the sprites to symbols and inside their respective symbols I placed the remaining sprites. So it's like this:
Zombi (Main Symbol):
ZombiAttack (in Frame 1):
inside this I placed the remaining Zombie Attack sprites placed at intervals of 5 frames.
ZombiIdle (in Frame 15):
inside this I placed the remaining Zombie Idle sprites placed at intervals of 5 frames.
ZombiMove (in Frame 20):
inside this I placed the remaining Zombie Move sprites placed at intervals of 5 frames.
In the Zombi Class File I used the following code in the ENTER_FRAME listener's function:
this.gotoAndPlay(20); //For the moving animation of the Zombie.
This plays a static image of the frame 20 and not what's inside it (which I want it to play).
Now, my question is how do I do that? How do I play the nested symbols animation and control it further?
I've found a few posts that address a similar problem but the solution for them isn't working for me as many posts were dated back to 2004 and 2005.
Thanks in advance! :)
Make sure all your symbols are movieclips and give them instance names in the property inspector. (For example, you can name the idle animation "idle_mc").
You could place this actionscript on frame 15:
idle_mc.play();
To make sure that idle_mc plays after the playhead jumps to frame 15. You can also put a play(); command inside the idle animation on frame 1, just to make sure it plays.

Frame by Frame animation AS3

This is for AS3 FlashDevelop, Basically I'm super new to this. The most I've done in AS3 coding is display multiple images on a single frame and parallax images.
However I want to know how to display embedded Bitmap (.png pictures) as frames one after another,
like frame 1 = embedded image 1 frame 2 = embedded image 2 (frame 1 is gone but 2 shows) frame 3 = embedded image 3 (and so on.)
and they would continuously play as an animation and stop at the first frame until I press play again
I believe I would use nextFrame, stop and gotoframe but don't know where and what I need to code, I heard of bitmapdata but I'm stuck on how to use it in purpose of animating frame by frame.
EDIT: No I'm not animating sprites, rather it's more like cartoon process where you'll go frame by frame of the image files, as one appear the previous one disappears.
You could iterate through each frame and add the images after you load them.
If you do addChild() it should add it to the current frame you're on. Load the next image with a Loader, place it down with addChild, nextFrame(), and repeat until you have all the images. Then when they're all loaded (from what I guess would be some list you'd have in an array or an xml) take the user to frame 1. You might want to do this inside of a movieclip while having that and a cover graphic on your main stage so the user doesn't see all of the images while they're being loaded and placed.
[More about adding display objects to frames]

Actionscript 3 - lock the code from restarting while it loops

I am making a boardgames in flash, with a background with moving objects.
It goes on repeat, so they dont stop on the last frame, which in this case is 60 frames. Only problem is, the actionscript code which has its own layer, and exists on frame 1, resets every time it starts over again, logically enough. But then I loose all the data I´ve gained over the time of 60 frames.
Is there a way I can make the actionscript code unbound from the objects loop?
Cheers
On the last frame of your animation, add a bit of AS3 code to force skipping frame 1:
gotoAndPlay ( 2 );
When the playhead reaches the last frame, this line will execute and your animation will restart at frame #2, skipping the code on frame #1.

Actions are assigned to wrong keyframe in Flash CS5

I am working with Flash CS5, and haven't been using Flash since the age of AS2.
I have a movieclip symbol in which I have an Actions layer, in which I have a keyframe in frame 1 and one in frame 20. Each of these should have a stop(); action assigned, but when i select the one in frame 20 and start writing, the little "a" appears on frame 1 of another layer. When I make a keyframe in frame 20 of that layer and try to assign actions it yields the same result. They appear on frame 1.
Is this a bug or am I missing some vital information about AS3?
AS3 is in fact more picky (for good reason) about how the code is implemented.
You need to select the keyframe you are intending to put code into, and then use your actions window. And as Markus commented, make sure you're using keyframes, and not empty frames. If you try to write code into an empty frame, it will default it to the most recent keyframe.
Furthermore, If you have multiple layers and say, your code is on layer2 and your objects on layer1, if you have keyframes on layer1, and intend to enter code at frame 20, but your layer selection is layer2, it will yield the same result described above. You'll have to make sure the correct layer is active. The actions window will only display the code from the current layer's most recent keyframe.
Hope that clears some things up!