00:00
00:00
Newgrounds Background Image Theme

Arnahan just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

AS: Replay Buttons

13,682 Views | 29 Replies
New Topic Respond to this Topic

AS: Replay Buttons 2005-07-03 07:27:26


AS: Main

This basic tutorial covers on handlers, gotoAndStop, and is for the use of creating a replay button, I will use the most basic stuff I can in order to help practically rather then teach, this is mainly for practical people rather then people who want the actual learning.

I will not cover buttons themselves.

What to do?

Click the "Window" tab, and inside it click "Other Panels" and click "Buttons", a small panel will pop, now go to the last frame of your last scene, click the folders and find a button you would like, I recommand clicking "Circle Button". click the button you would like to use and drag it to the stage for the last frame of the last scene.

Now you have a button on your scene, you need ot make it do stuff ;)
Click the actions panel to open it, if it's not open click "Window"->"Development Panels"->"Actions"

click the button and make sure the Actions panel is now titled "button actions", you can write in it, now let's see what the code is.

first of all we need to tell the button WHEN to trigger, we can make it trigger when the mouse is over it, when it is released on it, when it is pressed on it, when a certein key is down, and many more, this is done by the "on" button handler

on(release) triggers when the mouse is released over the button
on(press) triggers when the mouse is pressed over the button

these are the main two we will use since they are the most common.

after a handler in flash we always use '{' brackets to specify the start and end location of the code that handler triggers, so generally

on(release){
<Code Here>
}

is the syntax we will use.

let's now look into the current frame manipulation flash provides us with, there are several
remarks are in //

stop(); //this action causes the movie to stop
play(); //this action causes the movie to play
nextFrame(); //this action cuases the movie to go to the next frame as stop
prevFrame();//same as nextFrame, only it goes to the previous frame
nextScene();//goes to the next scene and stops
prevScene();//goes to the prev scene and stops
gotoAndStop(<frameNumber>); //goes to a certein frame number (or label) and stops
gotoAndPlay(<frameNumber>); //goes to a certein frame number (or label), and plays
gotoAndStop(<scene>,<frameNumber>);//goes to a certein frame in a certein scene and //stops
gotoAndPlay(<scene>,<frameNumber>);//goes to a certein frame in a certein scene and //plays

the most powerful method is the one we will used, gotoAndPlay(<scene>,<frameNumber);
by placing this action, once triggered (when the on statement occurs) the flash movie will go to the given frame in the given scene

I will presume you want to go to the second frame in your first scene for replay

our actions were

on(release){

}

and we will now add the gotoAndPlay part

on(release){
gotoAndPlay("Scene 1",2);
}

the frame number can be a number between 1 and the total frames in the scene, the scene name must be accurate, it is case sensative, if you don't use scenes, drop it and use gotoAndPlay(<frameNumber); instead.

to find out the accurate scene name click "Window"->"Design Panels"->"Scene". use the scene name (case sensative) exactly as shown there.

for those of you who use movieclips, don't pkace this code anywhere in a movieclip for path reasons, the button must be on the base timeline

hope this helps.

ask any questions.

Inglor

p.s.
sorry for having to use the APS account again.

Response to AS: Replay Buttons 2005-07-03 07:49:43


Lol this really for the complete noobs

Response to AS: Replay Buttons 2005-07-03 07:53:25


or just people who are good with art but can't script stuff ;)

Response to AS: Replay Buttons 2005-07-15 06:11:53


Or people who are like me and stay up too late at night programming and start to lose their mind. I was trying to link to another scene with a basic button. You know, the same question we answer several times a day:

on (release) {
gotoAndPlay("Credits", 1);
}

AND IT WASN'T WORKING! I looked it up in the actionscript dictionary. I looked at this thread. I was going crazy labeling frames and trying gotoAndStop vs. gotoAndPlay. I was doing EVERYTHING and it wouldn't work, that is until I realized I kept doing test scene which aparently doesn't load the other scenes and therefore won't link to them even if you tell it to. Anyway, thats a little tip to anybody who might have the correct syntax and still be having problems. Always test your whole movie! I can't beleive I wasted 30 minutes of my life on that.

Response to AS: Replay Buttons 2005-08-28 17:30:07


http://www.newground../topic.php?id=335033
AS: Animated Buttons by Inglor

Response to AS: Replay Buttons 2005-08-28 17:34:53


oops, I was sure I am in AS: Main lol, used this as a reference in the new animated buttons one

Response to AS: Replay Buttons 2005-10-14 13:46:33


I know how to make replay buttons, but I'm making a parody of a free iPod banner (you know, like the ones you see all over this site), and I have the basic coding and everythinhg ready... I have the objects, the custom cursor and everything done, but there's one small problem: When you kill the target object, it cuts to a movie clip of the object dying. When it finishes dying, it stops (using the stop action script), and a replay button appears within the death movie clip. When you click it to replay, it just replays the movie clip.

How can I make the replay button refresh the actual flash game itself instead of simply replaying the movie clip? Or, is there some way to make a replay button appear in the middle of the flash game when the death movie clip is done playing?


Hey kids!

BBS Signature

Response to AS: Replay Buttons 2005-10-14 13:51:15


At 10/14/05 01:46 PM, von_Brunk wrote: stuff

Put _root at the front of the gotoAndPlay command on the button =P


Sup, bitches :)

BBS Signature

Response to AS: Replay Buttons 2005-10-14 14:12:31


At 10/14/05 01:51 PM, -liam- wrote:
At 10/14/05 01:46 PM, von_Brunk wrote: stuff
Put _root at the front of the gotoAndPlay command on the button =P

Where? Here's what mine looks like:

on(release){
gotoAndPlay("Scene 1", 1);
}


Hey kids!

BBS Signature

Response to AS: Replay Buttons 2005-10-14 14:13:58


Try changing it to this:

on(release){
_root.gotoAndPlay(1);
}

It will automatically goto Scene 1, Frame 1 if you don't specify a scene.


Sup, bitches :)

BBS Signature

Response to AS: Replay Buttons 2005-10-14 14:27:32


Ok, it sort of worked. I got the movie to replay from the beginning, but the movie clip that continuously loops around at the start of the movie is the last frame of the death animation (including the replay button), instead of the very start of the non-dead target.


Hey kids!

BBS Signature

Response to AS: Replay Buttons 2005-10-14 14:37:31


this tutorial is for noobz... ,but there are some noobz in NG BBS who will need this ;P
======================================

At 8/28/05 05:34 PM, Inglor wrote: oops, I was sure I am in AS: Main lol, used this as a reference in the new animated buttons one

lolzs ;D

Response to AS: Replay Buttons 2005-11-19 20:47:09


At 7/3/05 07:53 AM, Inglor wrote: or just people who are good with art but can't script stuff ;)

Like me, thousands of thanks for help! Gonna submit my movie tomorrow thanks to this topic.

Response to AS: Replay Buttons 2005-11-19 21:00:55


At 7/3/05 07:49 AM, T-H wrote: Lol this really for the complete noobs

What's a gotoAndPlay()? Can I use that to make platformers?

U guyz R 1337! R1t3 a c0d3 4 m3!

Nah Ing, I think it's a good thing. I didn't see any links in AS: Main that really went into the basic of basics. Good stuff.


Writer @ www.Johnrickett.com

Response to AS: Replay Buttons 2005-11-19 22:15:22


At 7/15/05 06:11 AM, BleeBlap wrote: I can't beleive I wasted 30 minutes of my life on that.

Oh BleeBlap, those 30 minutes weren't wasted, you learnt a very valuable lesson, NOW NEVER DISSAPOINT ME AGAIN, i dont want any AS errors from you, you hear!

Response to AS: Replay Buttons 2006-05-23 17:43:29


um how do u do it if its a botten im a noob

Response to AS: Replay Buttons 2006-05-24 13:46:37


Bump

all this action script will really come in handy when ever i get stuck.

Response to AS: Replay Buttons 2006-07-30 05:27:23


This doesn't work for Flash 8...I don't have a Buttons option in Other Libraries.

Response to AS: Replay Buttons 2006-07-30 06:25:30


At 7/30/06 05:27 AM, angelo_ryan wrote: This doesn't work for Flash 8...I don't have a Buttons option in Other Libraries.

So make your own button! All you've got to is draw something, convert it to a symbol, and select the 'button' option. Voila!


...

BBS Signature

Response to AS: Replay Buttons 2006-08-07 20:07:28


i have tryed every code here but it just come error!!
i want to have a replay button can someone help me im a noob :P


BBS Signature

Response to AS: Replay Buttons 2007-01-14 21:16:22


well it dosen't take a genuis to make a replay button
i figuired that out when i first started flash


|| DcOrP|| You can't spell harDCORe Porn without DCORP.

Bring Amber Lamps

BBS Signature

Response to AS: Replay Buttons 2007-03-31 15:12:29


yeah, it's easy, but my first mistake was stupid...
on(press){
gotoAndPaly(3);
}
I couldn't figure out what i'd done wrong, it took me 3 weeks to realise...

Response to AS: Replay Buttons 2007-07-19 11:57:09


well you did this tutorial really well considering how little there is to do!


If a man that always tells the truth comes up to you and says that another man always tells lies, and the man who always lies come up to you and says "I'm lying", then is he?

BBS Signature

Response to AS: Replay Buttons 2008-08-24 04:09:39


At 7/3/05 07:53 AM, Inglor wrote: or just people who are good with art but can't script stuff ;)

true that


Your parents told me to tell you that you are a douche

Response to AS: Replay Buttons 2009-08-24 16:27:58


thanks for this. I'm a total noob in AS...
Was just doing a replay button, but without success. I try this tutorial tomorrow.

I'm glad I found preloaders at Newgrounds here, otherwise I'd go totally nuts.

And yeah, sorry for beeing a noob. Reading commens like "omg, this is just for noobz!" http://www.newgrounds.com/bbs/post/reply /299751#

Response to AS: Replay Buttons 2009-08-24 16:46:37


Thanks, it helped me when I was a n00b.
(Pressed replay)
Thanks, it helped me when I was a n00b.


Super Sprite Fight Collab | The Kirby Collab | YouTube | Yup, the image is the header of my company.

BBS Signature

Response to AS: Replay Buttons 2009-11-12 13:46:56


I've been trying all fucking week to get this god damned Replay button to work, but it wont. I want it to go to Scene 1, frame 1, and it wont.

And i can't delete the extra scene I have at the end. ugh.

forgive me, I'm frutrated.

replay.addEventListener(MouseEvent.CLICK , onClick);

function onClick(event:MouseEvent):void
{
gotoAndPlay("Scene 1",1);
}

thats what I have so far, obviously not working. I just want it to go back to scene 1/frame1!! what sso hard about that!!! D'X

Response to AS: Replay Buttons 2009-11-12 14:10:39


At 11/12/09 01:46 PM, IaReFrEaKeeee wrote: rant

are you using AS2 or AS3. that code is AS3 and this tutorial is AS2


AS2||AS3||Motox

Thanks to hdxmike for the sig :]

BBS Signature

Response to AS: Replay Buttons 2009-11-12 15:09:55


yes, I'm using as3

oops. can u help anyways?

Response to AS: Replay Buttons 2009-11-20 03:08:09


At 7/30/06 05:27 AM, angelo-ryan wrote: This doesn't work for Flash 8...I don't have a Buttons option in Other Libraries.

just go to ''window'' then ''other libruaries'' then buttons should b in there