A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: AS3, Why does this work only once?

  1. #1
    Senior Member freshly's Avatar
    Join Date
    Dec 2003
    Location
    Toronto, Canada
    Posts
    439

    AS3, Why does this work only once?

    I have attached my source file....

    I have this code on the first frame in a MC

    Actionscript Code:
    stop();

    masker.y = -100;

    import flash.events.MouseEvent;

    infoBtn.addEventListener(MouseEvent.ROLL_OVER, infoBtnRollOver);
    infoBtn.addEventListener(MouseEvent.ROLL_OUT, infoBtnRollOut);
    infoBtn.addEventListener(MouseEvent.MOUSE_UP, infoBtnRollRelease);

    function infoBtnRollOver(event:MouseEvent):void{
        infoBtn.gotoAndStop(2);
        infoBtn.buttonMode = true;
    }
    function infoBtnRollOut(event:MouseEvent):void{
        infoBtn.gotoAndStop(1);
    }
    function infoBtnRollRelease(event:MouseEvent):void{
        infoBtn.gotoAndStop(1);
        gotoAndStop(2);
    }

    This code on the second frame in the same MC

    Actionscript Code:
    stop();

    masker.y = 0;

    //import flash.events.MouseEvent;

    infoBtn.addEventListener(MouseEvent.ROLL_OVER, infoBtnRollOver2);
    infoBtn.addEventListener(MouseEvent.ROLL_OUT, infoBtnRollOut2);
    infoBtn.addEventListener(MouseEvent.MOUSE_UP, infoBtnRollRelease2);

    function infoBtnRollOver2(event:MouseEvent):void{
        infoBtn.gotoAndStop(2);
        infoBtn.buttonMode = true;
    }
    function infoBtnRollOut2(event:MouseEvent):void{
        infoBtn.gotoAndStop(1);
    }
    function infoBtnRollRelease2(event:MouseEvent):void{
        infoBtn.gotoAndStop(1);
        gotoAndStop(1);
    }

    This works only once, WHY?

    Please help, many thanks in advance!
    Attached Files Attached Files
    Last edited by freshly; 02-12-2010 at 01:43 PM.

  2. #2
    Senior Member Robb@exo's Avatar
    Join Date
    Jun 2003
    Location
    Canada
    Posts
    1,540
    I modified your code, not much but enough to make it work. You have redundant code in the second frame, which should be cleared. Paste the below code into frame one and should operate.

    Actionscript Code:
    stop();

    masker.y = -100;

    infoBtn.addEventListener(MouseEvent.ROLL_OVER, infoBtnRollOver);
    infoBtn.addEventListener(MouseEvent.ROLL_OUT, infoBtnRollOut);
    infoBtn.addEventListener(MouseEvent.MOUSE_UP, infoBtnRollRelease);

    function infoBtnRollOver(event:MouseEvent):void{
        infoBtn.gotoAndStop(2);
        infoBtn.buttonMode = true;
    }
    function infoBtnRollOut(event:MouseEvent):void{
        infoBtn.gotoAndStop(1);
    }
    function infoBtnRollRelease(event:MouseEvent):void{
        infoBtn.gotoAndStop(1);
        gotoAndStop(2);
        if(masker.y == -100) {
            masker.y = 0;
        } else if(masker.y == 0) {
            masker.y = -100;
        }
    }
    Wile E. Coyote - "Clear as mud?"

  3. #3
    Senior Member freshly's Avatar
    Join Date
    Dec 2003
    Location
    Toronto, Canada
    Posts
    439
    works great thank for your help

    This will expand my AS3 horizons, lol

  4. #4
    Senior Member Robb@exo's Avatar
    Join Date
    Jun 2003
    Location
    Canada
    Posts
    1,540
    Glad I could help. Cheers!
    Wile E. Coyote - "Clear as mud?"

  5. #5
    Senior Member freshly's Avatar
    Join Date
    Dec 2003
    Location
    Toronto, Canada
    Posts
    439
    I have incorporated a slide to this if anyone is interested....

    Actionscript Code:
    var slider_y:Number = masker.y;

    infoBtn.addEventListener(Event.ENTER_FRAME, function(e:Event):void {
        var current_y:Number = masker.y;
        var slideTo_y:Number = current_y - slider_y;
        masker.y = current_y - (slideTo_y / 2.5);
    });

    slider_y = 0;

    //infoBtn.addEventListener(MouseEvent.ROLL_OVER, infoBtnRollOver);
    //infoBtn.addEventListener(MouseEvent.ROLL_OUT, infoBtnRollOut);
    infoBtn.addEventListener(MouseEvent.MOUSE_UP, infoBtnOnRelease);


    function infoBtnOnRelease(event:MouseEvent):void{
        if(slider_y == -100) {
            slider_y = 0;
        } else if(slider_y == 0) {
            slider_y = -100;
        }
    }

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