Stick Page Forums Archive

How to make a Play - Replay button in using AS3[Flash][Buttons]

Started by: wailwail | Replies: 8 | Views: 10,974

wailwail

Posts: 18
Joined: May 2013
Rep: 10

View Profile
Dec 9, 2013 6:30 PM #1120980
Hello guys !
This is my first tutorial , it is very simple , a tutorial about Play and Replay button . We are going to use ActionScript3 , if you are looking for AS2 , then you are at the wrong place , Ok , lets begin !

1) Open your .fla file , and then goto Insert -> New Symbol -> Type = button , Name = what you want to name it , i suggest " Play " and don't export it to ActionScript , and repeat for the Replay button

2) Design your button , you will see that there isn't frames any more , there is " Up - Over - Down - Hit "
Up - how does the button looks when you don't put your mouse over it
Over - how does the button looks when you put your mouse over it ( NOTE : without pressing )
Down - how does the button looks when you press it ( Or holding it )

3) Now , put it into the scene and write an Instance name for it , you will see that it has no effect , what are we going to do is adding an effect to it
Play - go to the first frame and right-click on it , then choose actions , copy and paste this to it and then i will explain
stop();

Playbutton.addEventListener(MouseEvent.CLICK,Playit);

function Playit(E:MouseEvent):void
{
play();
}

Now , the first line , stop(); - we use it to stop the animation or in other words , set the fps to 0
" Playbutton.addEventListener(MouseEvent.CLICK,Playit); "

Playbutton = the Instance name of the button in the scene ( you can change it to whatever your button's Instance name is )
addEventListener = adds a new event ( this is simple , see other Events tutorials because i won't explain this )
MouseEvent = there is many event types , like keyboard event ( just an example ) but here we are gonna use a MouseEvent
CLICK = of course not RELEASE or anything else
Playit = The name of the function , you can write here whatever you want , but make it simple and don't have Space's

" function Playit(E:MouseEvent):void "

function = because it is a function
Playit = the name of the function , remember " Playbutton.addEventListener(MouseEvent.CLICK,Playit); "
E:MouseEvent = since it is a mouse event , of course we will write " MouseEvent " , and E means Event

" play(); " play the animation or in other words , set the fps to the original one

Replay - - go to the last frame and right-click on it , then choose actions , copy and paste this to it and then i will explain

stop();

Replaybutton.addEventListener(MouseEvent.CLICK,Replayit);

function Replayit(E:MouseEvent):void
{
play();
}


Now , the first line , stop(); - we use it to stop the animation from looping again , and again , and again

" Replaybutton.addEventListener(MouseEvent.CLICK,Replayit); "

Replaybutton = the Instance name of the button in the scene ( you can change it to whatever your button's Instance name is )
addEventListener = adds a new event ( this is simple , see other Events tutorials because i won't explain this )
MouseEvent = there is many event types , like keyboard event ( just an example ) but here we are gonna use a MouseEvent
CLICK = of course not RELEASE or anything else
Replayit = The name of the function , you can write here whatever you want , but make it simple and don't have Space's

" function Replayit(E:MouseEvent):void "

function = because it is a function
Replayit = the name of the function , remember " Replaybutton.addEventListener(MouseEvent.CLICK,Replayit); "
E:MouseEvent = since it is a mouse event , of course we will write " MouseEvent " , and E , it means Event

" play(); "

So that the game plays again from frame 1
timberjake
2

Posts: 5
Joined: Dec 2013
Rep: 10

View Profile
Dec 11, 2013 10:05 AM #1121904
This was very informative, thanks for this and am so concern, Thanks for sharing your idea
RaWrz-Cupcakes44
2

Posts: 2,395
Joined: Dec 2012
Rep: 10

View Profile
Jan 20, 2014 3:53 AM #1144190
so complex but so resourceful
Splodervit
Banned

Posts: 20
Joined: Jan 2015
Rep: 10

View Profile
Feb 16, 2015 1:47 PM #1309687
I can't make this button!
in AS3, when i try to put the code in actions panel it appears:

In ActionScript 3.0, code cannot be placed directly in objects.


What i can do?
EclairCat

Posts: 854
Joined: Dec 2014
Rep: 10

View Profile
Feb 17, 2015 3:04 PM #1310408
well thanks
i always wanted to know how to make this :D
iam Irvin

Posts: 493
Joined: Nov 2014
Rep: 10

View Profile
Feb 17, 2015 4:16 PM #1310457
Quote from Splodervit
I can't make this button!
in AS3, when i try to put the code in actions panel it appears:



What i can do?


You copied or you wrote them yourself?
Splodervit
Banned

Posts: 20
Joined: Jan 2015
Rep: 10

View Profile
Feb 18, 2015 11:36 PM #1311324
Quote from iam Irvin
You copied or you wrote them yourself?

Sorry, I discovered that for the sript to work, it need to be written.
My bad :(
MaxxSafee

Posts: 5
Joined: Feb 2015
Rep: 10

View Profile
Feb 26, 2015 11:17 PM #1316590
Thanks, this is very helpful. :D
Hetorii

Posts: 39
Joined: Jan 2015
Rep: 10

View Profile
Feb 27, 2015 12:20 AM #1316640
This helped me
Website Version: 1.0.4
© 2025 Max Games. All rights reserved.