Help with buttons in AS3

Hi Folks,
I'm stuck with a simple flash movie I need to create in which two images fade in and fade out, and each of them must be clickable and hyperlink to a separate URL.
I've got the fading going okay, but I cannot for the life of me get even a single button to work on it.
If it's helpful I can send along what I've got so far.  Any assistance would be greatly appreciated.
Regards,
Andrew.

Hi Ned,
Thank you for the followup email.
I think I was close - I was aware of the changes between AS2 and AS3, but I
think I was putting the Action in the wrong place.
Next question - if I have 2 buttons (say btn1 and btn2), how do I make btn1
available for say frames 1-60, and btn2 available from frames 61-120?
I am primarily a ColdFusion developer, and a complete newbie to flash, so
sorry if this is a dumb question.
Regards,
Andrew.
2009/5/15 Ned Murphy <[email protected]>
In AS3, to make a button work with code, you need to add an event listener
for it.  In the timeline that holds that button, in a separate actions layer
that you create, in a frame numbered the same as where that button exists,
you would add the event listener:
>
btn1.addEventListener(MouseEvent.CLICK, btn1Click);
>
Descriptively, that line of code contains the following:
>
buttonInstanceName . displayObjectMethod (eventClass . eventType,
eventHandlerFunction);
>
The name of the function for processing the clicking of that button was
already defined at the end of the event listener assignment, so now you just
have to write that function out:
>
function btn1Click(evt:MouseEvent):void {
   var /String = "http://www.awebsite.com/awebpage.html";
   var req:URLRequest = new URLRequest(url);
   navigateToURL(req);
>

Similar Messages

  • NEED HELP WITH BUTTONS IN AS3!!

    Hello, I am stumped with an action scripting problem. I'm
    trying to create a really basic website in flash using buttons to
    jump from scene to scene. Let's say I want to do something as
    simple as make scene 1 jump to scene two right? I'll place in my
    scene 2 button on my first page:
    But instead of the scene changing to the next scene after I
    press the button, these errors come up!!
    1180: Call to a possibly undefined method on.
    1120: Access of undefined property release.
    1120: Access of undefined property _root.
    I've tried asking in so many different forums, I usually do
    pretty good with action scripting for buttons. But this is my first
    time doing it with cs3. I'm utterly confused, someone please help!!
    Thank you.
    The code on this page is the code I was using to try to
    change scenes...Oh! and whenever I try to put a code in the actual
    button, it won't let me. I just get a message that says something
    like "Can't have any actions applied to it".

    foxxpop,
    > But instead of the scene changing to the next scene
    > after I press the button, these errors come up!!
    >
    > 1180: Call to a possibly undefined method on.
    > 1120: Access of undefined property release.
    > 1120: Access of undefined property _root.
    You're using three terms that aren't supported in
    ActionScript 3.0: the
    on() function, the release parameter to that function, and
    _root. In
    ActionScript 3.0, you'll have to give your button an instance
    name and wire
    it up like this:
    http://www.quip.net/blog/2007/flash/making-buttons-work-in-flash-cs3
    In that blog entry, you'll see (with explanation) something
    that looks
    like this:
    myButton.addEventListener(
    MouseEvent.CLICK,
    function(evt:MouseEvent):void {
    trace("I've been clicked!");
    Just bear in mind that you can also make that a named
    function, like
    this:
    myButton.addEventListener(MouseEvent.CLICK, clickHandler);
    function clickHandler(evt:MouseEvent):void {
    trace("I've been clicked!");
    > I've tried asking in so many different forums, I usually
    do
    > pretty good with action scripting for buttons. But this
    is
    > my first time doing it with cs3.
    Your issue isn't Flash CS3, it's that your FLA file is
    configured for
    ActionScript 3.0. If you change that to AS2, you can go right
    on using the
    same approach you used to -- and you'll be able to attach
    code directly to
    objects. ;)
    David Stiller
    Co-author, The ActionScript 3.0 Quick Reference Guide
    http://tinyurl.com/2s28a5
    "Luck is the residue of good design."

  • Help with buttons and AS3

    I need urgent help for a college project, I've drawn a map and I have some photographs that appear on the map from the timeline one after another. I want the timeline to be activated when I press a Button On the map of where I've been on holiday but I have no Idea how to put it together.

    While I can offer a couple ideas, you'll need to spend some time figuring out how to use Flash... maybe get some formal training with it.
    For the photographs, create each set of them as a movieclip, and give each movieclip an instance name so that you can control its visibility using code.  Initially you will want to set the visible property of them all to false, likely done in the first frame of the timeline (ex: imageGrp1.visible = false; ).  Then you will use your buttons to make them visible.
    To code one of the buttons, you need to assign it an instance name as well.  Then you need to assign an event listener for that button to detect when it gets clicked, and an event handler function to go with the event listener... the listener calls the function into action when the event occurs.
    ex:
    // the event listener for a button with an instance name of imgGrp1Button...
    imgGrp1Button.addEventListener(MouseEvent.CLICK, showGrp1);
    // and the event handler function for the CLICK listener
    function showGrp1(evt:MouseEvent):void {
          imageGrp1.visible = true;
    If you want to hide any visible set when you select a new one, then you can create a function that sets them all visible = false and call that function both at the start in frame 1 and in each button event handler function (before you set the selected set to be visible).

  • Help with buttons :S

    hi all,
    i'm new to flash but i have an idea whats going on with webpages. I need some help with buttons! i have a website and its has a stage and 9 different flv's (screens). I've been trying to read online and i can't find out how to navigate to different screens, example below
    home          |            |
    about us     |  stage   |
    contact       |            |
    you click one one button it updates the stage. also i'm using actionscript 2.0.
    thanks for any help ahead of time
    Thank you,

    Is it a wi-fi or cellular connection that isn't working?  If its wi-fi and other people/computers/phones can connect check your settings.  If its cellular, are other people's phones (on the same carrier) working in the same location? If other people can't connect then it is likely a network problem.  If others can you may need to reset/restore you iPhone.

  • Help with unloading images AS3

    Please can anyone help me. I am new to Action Script and flash and am having a nightmare unloading images. The code below works but I keep getting the following error messages:
    TypeError: Error #2007: Parameter child must be non-null.
    at flash.display::DisplayObjectContainer/removeChild()
    at index_fla::MainTimeline/clickSection()
    ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
    at flash.display::DisplayObjectContainer/removeChild()
    at index_fla::MainTimeline/clickSection()
    Any help with this would be much appreciated.
    var ImgReq01:URLRequest=new URLRequest("images/home/01.jpg");
    var ImgReq02:URLRequest=new URLRequest("images/home/02.jpg");
    var ImgReq03:URLRequest=new URLRequest("images/home/03.jpg");
    var ImgReq04:URLRequest=new URLRequest("images/home/04.jpg");
    var ImgReq05:URLRequest=new URLRequest("images/home/05.jpg");
    var imgList:Array=[ImgReq01,ImgReq02,ImgReq03,ImgReq04,ImgReq05];
    var imgRandom = imgList[Math.floor(Math.random()* imgList.length)];
    var imgLoader:Loader = new Loader();
    imgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
    imgLoader.load(imgRandom);
    function onComplete(event:Event):void
      var randomImage:Bitmap = Bitmap(imgLoader.content);
      randomImage.x=187.4;
      randomImage.y=218.1;
      addChild(randomImage);
    //handle events for info buttons...
    information. addEventListener (MouseEvent.CLICK, clickSection);
    home. addEventListener (MouseEvent.CLICK, clickSection);
    galleries. addEventListener (MouseEvent.CLICK, clickSection);
    function clickSection (evtObj:MouseEvent) {
    //Trace shows what's happening.. in the output window
    trace ("The "+evtObj.target.name+" button was clicked")
    //go to the section clicked on...
    gotoAndStop (evtObj.target.name)
    // this line is causing errors when navigating between the gallery and information buttons
    var Image:Bitmap = Bitmap(imgLoader.content);
      removeChild(Image);

    you really should be adding the loader to the displaylist, not the content.
    try:
    var ImgReq01:URLRequest=new URLRequest("images/home/01.jpg");
    var ImgReq02:URLRequest=new URLRequest("images/home/02.jpg");
    var ImgReq03:URLRequest=new URLRequest("images/home/03.jpg");
    var ImgReq04:URLRequest=new URLRequest("images/home/04.jpg");
    var ImgReq05:URLRequest=new URLRequest("images/home/05.jpg");
    var imgList:Array=[ImgReq01,ImgReq02,ImgReq03,ImgReq04,ImgReq05];
    var imgRandom = imgList[Math.floor(Math.random()* imgList.length)];
    var imgLoader:Loader = new Loader();
    imgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
    imgLoader.load(imgRandom);
    function onComplete(event:Event):void
    imgLoader.x=187.4;
    imgLoader.y=218.1;
      addChild(imgLoader);
    //handle events for info buttons...
    information. addEventListener (MouseEvent.CLICK, clickSection);
    home. addEventListener (MouseEvent.CLICK, clickSection);
    galleries. addEventListener (MouseEvent.CLICK, clickSection);
    function clickSection (evtObj:MouseEvent) {
    //Trace shows what's happening.. in the output window
    trace ("The "+evtObj.target.name+" button was clicked")
    //go to the section clicked on...
    gotoAndStop (evtObj.target.name)
    // this line is causing errors when navigating between the gallery and information buttons
    if(this.contains(imgLoader){
      removeChild(imgLoader);

  • Help with button code please?

    I am a novice and have just completed my first animated movie. I need help with action script.
    The movie is currently looped and I have created and invisible button the size of the frame with the intention that a user can click on the movie image to stop it and on second click continue the movie from where it stopped.
    I have used the AS event handler method to stop the movie. I have tested it and it works. But I cannot figure suitable code to restart the movie.
    Two questions;
    1. am I going about the task the right way? (should I use two buttons, one stop, one start)?
    2. if my approach is feasible, can anyone give me the correct AS to re-start the movie and put me out of my misery please?

    you can use the following after changing "yourbutton" and "yourmovieclip" to use suitable instance names:
    yourbutton.onRelease=function(){
    if(!this.toggle){
    yourmovieclip.stop();
    } else {
    yourmovieclip.play();
    this.toggle=!this.toggle;

  • Help with buttons accessing loaded layers

    Hi all...Using Flash CS3 and AS3 to build a learning module that will load different layers of SWF files based on buttons on the main screen.  Got this working with no problems.  What I want to do is add buttons to provide learners some functionality, specifically a forward button, back button and a check box that will keep advancing automatically.  I've done massive searches and so far nothing seems to work.  Seems like what I am acccessing so far is the main layer, not the new layers as they are loaded.  Below is what I have been trying with the back button; the foward button uses nextFrame and is Handler2.  It isn't working.  Not even sure how to start with the checkbox for auto advance.  Any help would be GREATLY appreciated.
    Mark
    back_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler1);
    function mouseDownHandler1(event:MouseEvent):void
                    MovieClip(root).prevFrame();

    Thank you for your reply.  This is what I have so far - the module has four differentSWFs that load depending on what the user selects.  The modules are titled Introduction, Standards, Elements, and Traits.  When clicked, the button loads that specfic SWF and the previous one is unloaded. Hope I am using the correct terminology - I'm more familiar with AS2 than 3!

  • Help with buttons in photo gallery

    Hello all
    I am trying to find a more effeicent way to place buttons on each of my pages (Photo Gallery SIte). I have 150 pages and constantly have to link each button to the "next" or "last" button. Is there a more efficent way to for me to ad butons to each page.My site is Blazinginterest.com
    Please give me some feedback on my site, possibly add a picture viewer?
    Thank you, HD

    what code do you already have? Maybe we can help you modify
    it where it's not working.
    Also, how do you have it currently laid out? eg. do you have
    several images on the screen, but some method to scroll through
    other images? Have you done a search here or on director-online.com
    (in the forum or articles section) on similar questions? Do you
    have something written up to describe what features you need such
    as a design document?
    Just trying to get a sense of your level of programming in
    general, experience with Director and what planning/details you
    have worked out so far because there are so many different ways to
    program a gallery.

  • Need help with buttons in applet

    stupid question maybe but i'm a beginner, and hey..there are no stupid questions, right? well, i may prove that wrong...anyway...
    I can't relocate a button, or any other component for that matter. When I try to make a simple applet with just one button showing, then it works perfect...but when I make the applet a little bigger with some graphcis and text, the setLocation() and setSize() methods don't work. the wierd part is that I don't get an error message, the compiler just ignores those lines...so it seems anyway.
    If anyone can help me I'd be very greatful
    thanx a lot

    Do you know there are 5 layout managers in java. It is probably worth looking through each one and the commands they use.
    The layout is determined by two things:
    1.position Components are added
    2.Layout manager used
    Ive never had to use setLocation() and setSize() as the layouts do it for you:
    1.Flowlayout: which is the default pane. e.g.
    setLayout(new Flowlayout()).
    2.GridLayout: postions panels into rows and columns
    b.GridBagLayout
    3.Borderlayout(NORTH,SOUTH,EAST,WEST and CENTER) postions in applet.
    4.CardLayout(a bit like a slideshow)
    5.Insets() which is used to determine top,bottom,left and right.
    Don't bother about 4 or 5 yet. But definitly have a look at the other 3.
    e.g. setLayout(new BorderLayout());
    add("North", new Button("ok"));
    add("CENTER", new Button("Exit");
    etc..

  • Need help with buttons in a phone simulation

    Hello
    I have built a telephone interface to be used for training in a Call Center.
    I am attempting to allow the user to press on the numberpad to enter passwords and such.
    It is only a simulation and will only work if the user presses the correct buttons.
    I am able to create the simulation when the user presses different buttons such as 1234
    but I need them to press 0000 (zero 4 times)
    I am not sure how to do this...
    I have been playing around with the advanced actions, which has allowed me to accomplish the hide and show actions when the user clicks a button, but wondering if there is a way I can
    have them click the 0 on the dialpad so each time it brings up the next zero
    once its gets to the 4th one, it will advance to the next slide...
    Hope that makes sense
    I appreciate any help or advice
    thanks
    Melissa

    Hi there,
    What I did, I took a variable 'counter123' and assign '0' value to this variable.
    I then added a button with Advanced action, I am sharing the Screenshot of the advanced action panel.
    Screen shot 1 :
    Incrementing the Value on click :
    The value of the variable should increase on every click, so lets add a true statement as a condition.
    Screenshot no 2 :
    As normally on buttons/click boxes, the project will continue as soon we click them.
    lets compare the value of our variable and then pause the project.
    Screen shot 3 :
    last if our purpose is solved, here we have clicked the button 4 times, so that has updated the value of our counter to 4, so as soon as the counter exceeds the value, we want the project to continue.
    please let me know if this helps you.
    This will help you in pressing a button 4 times, and i think you can also add actions to show and hide 'zeros' in your project.
    I find such scenarios very interesting and I always find help on Lilybiri's Blog : http://lilybiri.posterous.com/
    Thanks

  • Help with Buttons in Actionscript 2

    Help!! I am creating a Flash movie with 5 scenes. I have
    buttons for each that I have added actionscript to, but they still
    do not work. I am not getting any error messages. I am using
    actionscript 2 and have gone step by step. here is what i have :
    on (release) {
    gotoAndStop("main", 1);
    on (release) {
    gotoAndStop("blackboard", 1);
    etc for the rest of the buttons. Any help would save me much
    stress as I am trying to finish a project for school!!! thanks
    ah

    Try adding _root. before the gotoAndStop command. If you have
    the code on the buttons that is.

  • Help with buttons/actionscript

    I've got a movieclip acting as a button.  Code on the button itself handles roll-over/-out states, and I define an onRelease function in the main timeline as follows:
    backBut.onRelease=function(){
         gotoAndPlay(1);
    This code takes the movie back to the first frame and works on the third frame.  For some reason, though, the same code on the fifth frame has no effect.  The button doesn't do anything.  I have tried using the same button, I tried inserting a new keyframe with a new button, renaming the button, etc. and for some reason I just can't get it to work on the fifth frame.
    If it helps to visualize, I am essentially making a menu.  The first frame contains buttons to take you to submenus, located on following slides.  This button to go back to the original menu is on each frame with a submenu, but for some reason only works on one of them.  Thanks in advance for your help.

    Try moving that button in frame 5 to it's own layer.  If it's the same llibrary symbol, what happens is the name from the preceding instance gets inherited, along with other characteristics.  If frame 4 doesn't do anything, instead of a new layer, just try putting a blank keyframe between the buttons in frames 3 and 5.  This may not be the problem at all, but it's my first guess at the possible problem.

  • Need help with buttons that react to rollover that create a scoll effect

    hey everyone,
    I'm new to flash and actionscript and am having trouble
    creating what I need. I want to create a scroll area that scrolls
    left and right when you rollover a left or right arrow. what I want
    to scroll looks like a piece of film negative that has about 20
    thumbnails in it. I only want it to show about 4 thumbs at once
    though (thus the scroll is needed). so when the mouse rolls over
    the arrows, it scrolls, and when it rolls out it stops in place.
    eventually, i will add links to the thumbs for a better image.
    I've checked out a couple tutorials on scrollbars and such
    thinking that I can just go in and modify the code a bit, but the
    two turorials i've tried to do have left some of the pieces out...
    not very helpful when you don't know actionscript well. does
    anybody have any tips or ideas?

    Hi there,
    What I did, I took a variable 'counter123' and assign '0' value to this variable.
    I then added a button with Advanced action, I am sharing the Screenshot of the advanced action panel.
    Screen shot 1 :
    Incrementing the Value on click :
    The value of the variable should increase on every click, so lets add a true statement as a condition.
    Screenshot no 2 :
    As normally on buttons/click boxes, the project will continue as soon we click them.
    lets compare the value of our variable and then pause the project.
    Screen shot 3 :
    last if our purpose is solved, here we have clicked the button 4 times, so that has updated the value of our counter to 4, so as soon as the counter exceeds the value, we want the project to continue.
    please let me know if this helps you.
    This will help you in pressing a button 4 times, and i think you can also add actions to show and hide 'zeros' in your project.
    I find such scenarios very interesting and I always find help on Lilybiri's Blog : http://lilybiri.posterous.com/
    Thanks

  • Need help with buttons

    stupid question maybe but i'm a beginner, and hey..there are no stupid questions, right? well, i may prove that wrong...anyway...
    I can't relocate a button, or any other component for that matter. When I try to make a simple applet with just one button showing, then it works perfect...but when I make the applet a little bigger with some graphcis and text, the setLocation() and setSize() methods don't work. the wierd part is that I don't get an error message, the compiler just ignores those lines...so it seems anyway.
    If anyone can help me I'd be very greatful
    thanx a lot

    Boss,
    there is something called Layout Management in Java,
    see types of layouts in the Java API.
    Applet default is FlowLayout,
    so modify your layouts and try,
    u need a basic understanding and reading of Layouts
    in Java..take a tutorial...
    gud luck!

  • Need help with Buttons/Events

    HI
    Here is what I am doing. I am creating an "operations"
    calendar for my workplace. So far I have been successful with
    creating the page, inserting links, tags, images etc.....
    But now I want to add an Event button - where once the button
    is clicked - it will launch a script on my UNIX server.
    Cant quite figure this one out
    Any help would be greatly appreciated

    Hey man, I 've done some correction, and it seems work, why don't you try the code to see if it is what you want.
    import java.awt.*;
    import java.applet.*;
    import java.awt.event.*;
    public class ComplexMenu11 extends Applet implements ActionListener {
    Button open, close;
    MenuFrame f;
    public void init() {
    open = new Button("Open");
    add(open);
    open.addActionListener(this);
    close = new Button("Close");
    add(close);
    close.addActionListener(this);
    f = new MenuFrame("A Complex menu");
    f.setSize(200, 200);
    f.show();
    public void actionPerformed(ActionEvent evt) {
    if(evt.getSource() == open) {
    if(f.isShowing())
    f.show();
    }else{
    if(!f.isShowing())
    f.hide();
    class MenuFrame extends Frame implements ActionListener{  //and implements here too
    Font font;
    Label l;
    int fontsize;
    //MessageDialog md;
    MenuBar mb = new MenuBar();
    Menu m1 = new Menu("Colours");
    MenuFrame(String name) {
    super(name);
    m1.add(new MenuItem("White"));
    m1.add(new MenuItem("Light grey"));
    m1.add(new MenuItem("Yellow"));
    Menu m2 = new Menu("Font");
    m2.add(new MenuItem("10"));
    m2.add(new MenuItem("12"));
    m2.add(new MenuItem("14"));
    m2.add(new MenuItem("16"));
    m2.add(new MenuItem("18"));
    m2.add(new MenuItem("Message"));
    mb.add(m1);
    mb.add(m2);
    setMenuBar(mb);
    m1.addActionListener(this); //Add listener here
    l = new Label("A frame demonstration", Label.CENTER);
    add("South", l);
    //md = new MessageDialog(this,"Name",true);
    public void actionPerformed(ActionEvent evt) {
    if(evt.getSource() instanceof MenuItem) {
    //fontsize = 18;
    String label = evt.getActionCommand();
    if(label.equals("White")) {
    //setBackground(Color.white);
    System.out.println("This is the white point");
    }

Maybe you are looking for

  • Unable to update iPad 2 software and it's still in recovery mode.

    I have been noting some weird behavior on my iPad 2 I so tried to update my iPad to to iOS 6. Before doing it I tried to sync my apps to iTunes so I would not lose anything. I was unable to sync and a got a message that said "Unable to sync because t

  • Auto Focus in List Tile View in iPad : AGENTRY

    Hi All, I am facing a critical problem. I have a screen with two List tile view. The object assigned to the screen is MainObject and the two List tile views display Collection1 and Collection2. Now the requirement is user should select an object from

  • Assigning a value to a number field through a button

    11gxe , apex 4.x , hi all , i am trying to assign value to a number field through a button , i created a button , then a dynamic action for this button , when it is clicked , the dynamic action is based on Pl\Sql code , and the code is begin :p2_assi

  • Mac Test Server set up issues

    first day notes: I've spent the last two days transitioning into Dreamweaver and setting up my test server MySQL PHP and Apache by following online help, tutorials and recommendations. I've Terminaled MAMPed, and installed more crap than I wanted to

  • Question about Level Meter Plug in

    I know how to change the channel meter between pre/post fader metering is there a way to do this with Logic's Level Meter plug in and with Inspector?