A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Buttons - what am I doing wrong? (cs5)

  1. #1
    Junior Member
    Join Date
    Jun 2006
    Posts
    2

    Buttons - what am I doing wrong? (cs5)

    I have created a button> It has multiple instances with the same name - I want to be able to use the instance to go to a specific part of the movie whenever I click it however the location of the button changes. I created a function called "cancel" which when called goes to the cancel label. I thought this would be pretty straightforward but I've been stumped all day. The button will only work once and that is on frame 10. All other instances of this button don't work. Further, once you advance past frame 10 and go back, the button no longer works. I've wasted HOURS on this and cannot figure out what I'm doing wrong. I've attached the AS. - the button is called cancel with multiple instance titled Cancel1 on every 5th frame. The button changes location which is why I've done this. When I don't need the button to be active, I insert a clear keyframe on the button layer. Thanks for your mercy!

    Actionscript Code:
    //fscommand("allowscale", false);
    //fscommand("showmenu", false);
    //Stage.scaleMode = "noScale";
    //Stage.showMenu = False;

    /*This will stop the playback*/
    stop();

    /*This sets up the Button Actions for forward, back, and beginning. Each button is named accordingly followed by an EventListener which will wait for the Clicking mouse event before running the function.*/
    ForwardButton.addEventListener(MouseEvent.CLICK, ForwardAction);
    BackButton.addEventListener(MouseEvent.CLICK, BackAction);
    BeginningButton.addEventListener(MouseEvent.CLICK,BeginningAction);
    Continue1.addEventListener(MouseEvent.CLICK,continueHandler1);
    Cancel1.addEventListener(MouseEvent.CLICK,CancelSetup);

    /*These are the functions that run when there is a clicking mouse event on the button. The ForwardAction checks that the current frame is not the end (in this case 125 or more) before stepping ahead 5 frames to the next image.  The BackAction checks that the current frame is not the beginning (in this case 5 or less) before stepping back 5 frames to the previous image. The BeginningAction moves the playback to frame 1.*/
    function ForwardAction(E:MouseEvent):void {
        if (currentFrame >= 195){
            stop();
        }else{
            gotoAndStop(currentFrame + 5);
            ButtonCheck();
        }
    }
    function BackAction(E:MouseEvent):void {
        if (currentFrame <= 5){
            stop();
        }else{
            gotoAndStop(currentFrame - 5);
            ButtonCheck();
        }
    }
    function BeginningAction(E:MouseEvent):void {
        gotoAndStop(1);
    }
    function continueHandler1(E:MouseEvent):void {
    gotoAndStop(15,"Scene 1");
    }

    function CancelSetup(E:MouseEvent):void {
    gotoAndStop("cancel");
    }


    /*This section will disable the Forward and Back buttons when necessary.*/
    ButtonCheck();
    function ButtonCheck():void{
        if (currentFrame >= 190){
            ForwardButton.alpha = .25;
        }else{
            ForwardButton.alpha = 1;
        }
        if (currentFrame <= 5){
            BackButton.alpha = .25;
        }else{
            BackButton.alpha = 1;
        }
    }

  2. #2
    Flash/Flex Developer samac1068's Avatar
    Join Date
    Apr 2007
    Location
    Here, no there
    Posts
    1,813
    Did you say you have multiple instances of the same button with the same name? If so, then that is the reason. If you are running on the same timeline, then I would use only one instance of the button and move it to the new location when it reaches that frame.

    This way to avoid having to give each new button its own unique name.
    Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center