FORUMS: list search recent posts

create a NEXT button

COW Forums : Adobe Flash

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Daniel Katich
create a NEXT button
on Oct 16, 2012 at 8:12:30 pm

Hello All, My first post on this forum. I am rather new to Flash, and to ActionScript 3.0. Anyway, I want to know how youcreat a "next" button in Flash?
For example, your in a chatroom and you don't want to speak to this person you click the next button. I have googled this, and read other websites but unable to find the answer. If you have knowledge on how this please answer!!

Return to posts index

Sam Mattern
Re: create a NEXT button
on Oct 19, 2012 at 1:20:46 pm

Draw your button, select it and press F8. This brings up a dialog asking if you want to convert it to a MovieClip, Button, or Graphic. You can choose MovieClip or Button. I tend to choose MovieClip because I feel it gives me more control, but button will also work. Give it a name and click okay.

Now you have a button on your screen, but no way to associate code to it. So select your button and on the Properties tab, there is a spot called "Instance name." Here name it something like "next_btn." I do recommend the "_btn" suffix, specifically because it will help code hints work.

Now you can reference your button with code. Create a new layer on your timeline for your actions and add a keyframe on that layer if there isn't already one. Click on that keyframe and open the actions window (F9). Now you can add code to make your button operate.

There are two steps: 1. Add a listener that listens for events happening to that button (rollover, rollout, click, etc). 2. Create an action associated for that event.

The listener would look something like:
next_btn.addEventListener(MouseEvent.CLICK, goToNextPage);

The first part of the listener is WHAT you are listening for. There are a number of options here. The second part is the name of the function you are calling when that event triggers.

The function would look something like:
function goToNextPage(e:MouseEvent):void{
//add your code for what happens when you click next

The most important piece of your function is having the "e:MouseEvent" in parenthesis after your function name. This is because all event listeners pass the event as a variable when calling your function. What this means is you have to write your function to accept that event, even though you'll probably not use the variable. In this case "e" is the name we're giving the variable being passed from the listener, ":" means "I'm defining 'e' as type", and "MouseEvent" is the type of variable we're defining "e" as. If you don't include this, you'll get an error message.

Best practice would be to remove the event listener for the button once you no longer need it (next button no longer is active). You accomplish that by the reverse of adding it:
next_btn.removeEventListener(MouseEvent.CLICK, goToNextPage);

Sorry for the long explanation. Hope this was clear and helps.


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 All Rights Reserved