Forum Topic: AS: Replay Buttons

(6,822 views • 29 replies)

This topic is 1 page long.

<< < > >>
InglorAntiPostLimit NEUTRAL LEVEL 03

Sign-Up: 11/23/02

Posts: 71

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.


None

T-H

Reply To Post Reply & Quote

Posted at: 7/3/05 07:49 AM

T-H LIGHT LEVEL 39

Sign-Up: 01/07/04

Posts: 4,893

Lol this really for the complete noobs


None

Inglor

Reply To Post Reply & Quote

Posted at: 7/3/05 07:53 AM

Inglor NEUTRAL LEVEL 17

Sign-Up: 01/26/03

Posts: 10,948

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


None

BleeBlap

Reply To Post Reply & Quote

Posted at: 7/15/05 06:11 AM

BleeBlap LIGHT LEVEL 24

Sign-Up: 03/08/05

Posts: 944

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.


None

Inglor

Reply To Post Reply & Quote

Posted at: 8/28/05 05:30 PM

Inglor NEUTRAL LEVEL 17

Sign-Up: 01/26/03

Posts: 10,948

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


None

Inglor

Reply To Post Reply & Quote

Posted at: 8/28/05 05:34 PM

Inglor NEUTRAL LEVEL 17

Sign-Up: 01/26/03

Posts: 10,948

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


Questioning

von-Brunk

Reply To Post Reply & Quote

Posted at: 10/14/05 01:46 PM

von-Brunk EVIL LEVEL 41

Sign-Up: 03/18/03

Posts: 940

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

None

liaaaam

Reply To Post Reply & Quote

Posted at: 10/14/05 01:51 PM

liaaaam NEUTRAL LEVEL 22

Sign-Up: 12/11/04

Posts: 14,530

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

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


Questioning

von-Brunk

Reply To Post Reply & Quote

Posted at: 10/14/05 02:12 PM

von-Brunk EVIL LEVEL 41

Sign-Up: 03/18/03

Posts: 940

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

None

liaaaam

Reply To Post Reply & Quote

Posted at: 10/14/05 02:13 PM

liaaaam NEUTRAL LEVEL 22

Sign-Up: 12/11/04

Posts: 14,530

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.


Shouting

von-Brunk

Reply To Post Reply & Quote

Posted at: 10/14/05 02:27 PM

von-Brunk EVIL LEVEL 41

Sign-Up: 03/18/03

Posts: 940

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

None

Zielak

Reply To Post Reply & Quote

Posted at: 10/14/05 02:37 PM

Zielak FAB LEVEL 17

Sign-Up: 09/21/05

Posts: 865

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


None

Joevan

Reply To Post Reply & Quote

Posted at: 11/19/05 08:47 PM

Joevan NEUTRAL LEVEL 11

Sign-Up: 08/05/05

Posts: 95

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.


None

Johnny

Reply To Post Reply & Quote

Posted at: 11/19/05 09:00 PM

Johnny DARK LEVEL 21

Sign-Up: 04/17/04

Posts: 4,384

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.

All sites currently down. Deal with it. <3

BBS Signature

None

RWS

Reply To Post Reply & Quote

Posted at: 11/19/05 10:15 PM

RWS FAB LEVEL 23

Sign-Up: 03/11/05

Posts: 494

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!


None

XenNetwork

Reply To Post Reply & Quote

Posted at: 5/23/06 05:43 PM

XenNetwork NEUTRAL LEVEL 04

Sign-Up: 10/02/04

Posts: 128

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


None

PowerRangerYELLOW

Reply To Post Reply & Quote

Posted at: 5/24/06 01:46 PM

PowerRangerYELLOW FAB LEVEL 15

Sign-Up: 01/01/04

Posts: 4,345

Bump

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


None

angelo-ryan

Reply To Post Reply & Quote

Posted at: 7/30/06 05:27 AM

angelo-ryan LIGHT LEVEL 08

Sign-Up: 05/06/06

Posts: 74

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


None

edit-undo

Reply To Post Reply & Quote

Posted at: 7/30/06 06:25 AM

edit-undo LIGHT LEVEL 18

Sign-Up: 01/17/06

Posts: 1,776

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!

lolsigtrend
i just wanna fit in :'(

BBS Signature

None

Areek

Reply To Post Reply & Quote

Posted at: 8/7/06 08:07 PM

Areek DARK LEVEL 06

Sign-Up: 08/07/06

Posts: 38

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

None

DCorp

Reply To Post Reply & Quote

Posted at: 1/14/07 09:16 PM

DCorp DARK LEVEL 16

Sign-Up: 11/25/06

Posts: 1,102

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.
The Intelligent Thing To Do||My Youtube Chanel||How To Properly Drive, Done By Ghostly

BBS Signature

None

Grim-The-Unholy

Reply To Post Reply & Quote

Posted at: 3/31/07 03:12 PM

Grim-The-Unholy DARK LEVEL 08

Sign-Up: 02/24/05

Posts: 222

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...


None

DragonFruit-Rock

Reply To Post Reply & Quote

Posted at: 7/19/07 11:57 AM

DragonFruit-Rock EVIL LEVEL 13

Sign-Up: 12/31/05

Posts: 1,248

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

Winking

st91

Reply To Post Reply & Quote

Posted at: 8/24/08 04:09 AM

st91 DARK LEVEL 06

Sign-Up: 08/20/08

Posts: 13

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


Expressionless

Dayu

Reply To Post Reply & Quote

Posted at: 8/24/09 04:27 PM

Dayu NEUTRAL LEVEL 01

Sign-Up: 06/21/09

Posts: 1

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#


Elated

MarioFlashMovies

Reply To Post Reply & Quote

Posted at: 8/24/09 04:46 PM

MarioFlashMovies LIGHT LEVEL 13

Sign-Up: 11/26/07

Posts: 648

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

Yes, I have a Kirby Collab and Luigi Dies Collab 2 that haven't frozen. Also, why in the holy mother of shit I never win an award?! Dang it!

BBS Signature

Mad as Hell

IaReFrEaKeeee

Reply To Post Reply & Quote

Posted at: 11/12/09 01:46 PM

IaReFrEaKeeee EVIL LEVEL 13

Sign-Up: 03/09/06

Posts: 317

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


None

Yambanshee

Reply To Post Reply & Quote

Posted at: 11/12/09 02:10 PM

Yambanshee DARK LEVEL 10

Sign-Up: 10/05/08

Posts: 1,540

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

None

IaReFrEaKeeee

Reply To Post Reply & Quote

Posted at: 11/12/09 03:09 PM

IaReFrEaKeeee EVIL LEVEL 13

Sign-Up: 03/09/06

Posts: 317

yes, I'm using as3

oops. can u help anyways?

Elated

Chinnaru

Reply To Post Reply & Quote

Posted at: 11/20/09 03:08 AM

Chinnaru LIGHT LEVEL 04

Sign-Up: 02/06/09

Posts: 1

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


All times are Eastern Standard Time (GMT -5) | Current Time: 12:19 PM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!