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