Skip to main content
Known Participant
April 2, 2013
Answered

how to animate a mc by button in over state

  • April 2, 2013
  • 2 replies
  • 1606 views

hi

i have this cinema tabe movie clip with instance name tape

and two button

one for next and one for the previous

i want the next button every time (only when over state happen) the cinema tape crose the screen to get the next and the next atc,

and the back button  every time when over state happen the cinema tape get back and back atc,

i try

button_1.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandler);

function fl_MouseOverHandler(event:MouseEvent):void

{

tape.addEventListener(Event.ENTER_FRAME, fl_AnimateHorizontally_3);

function fl_AnimateHorizontally_3(event:Event)

{

          tape.x -= 10;

}

}

but the tabe across the screen completly !

This topic has been closed for replies.
Correct answer Ned Murphy

Do not nest the fl_AnimateHorizontally_3 function inside the fl_MouseOverHandler function, keep it separate from it.

It is not clear what problem you are having when you say "but the tabe across the screen completly !", but here are a few things...

1) You need to assign a starting position when the rollover occurs

2) You need to assign a MOUSE_OUT listener to stop the ENTER_FRAME and reset the tape position

3) You need to put conditions on how far the tape moves before it stops.

button_1.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandler);

function fl_MouseOverHandler(event:MouseEvent):void

{

         tape.x = 0;

         tape.addEventListener(Event.ENTER_FRAME, fl_AnimateHorizontally_3);

         button_1.addEventListener(MouseEvent.MOUSE_OUT, fl_MouseOutHandler);

}

function fl_AnimateHorizontally_3(event:Event)

{

          if(tape.x < stage.stageWidth){

              tape.x += 10;

          }

}

function fl_MouseOutHandler(event:MouseEvent):void

{

         tape.x = 0;

         tape.removeEventListener(Event.ENTER_FRAME, fl_AnimateHorizontally_3);

         button_1.removeEventListener(MouseEvent.MOUSE_OUT, fl_MouseOutHandler);

}

2 replies

Inspiring
April 3, 2013

also, be clear about how MOUSE_OVER differs from ROLL_OVER.

If your button contains any other MovieClips you will run into trouble.

ROLL_OVER is in most cases the "better" option

Known Participant
April 3, 2013

in both cases

when i reched the start of the tape

or the end of the tabe

i got the same error msg

TypeError: Error #1009: Cannot access a property or method of a null object reference.

          at Untitled_fla::MainTimeline/fl_MouseOutHandler()

the code

button_1.addEventListener(MouseEvent.ROLL_OVER, fl_MouseOverHandler);

function fl_MouseOverHandler(event:MouseEvent):void

{

         tape.x = 0;

         tape.addEventListener(Event.ENTER_FRAME, fl_AnimateHorizontally_3);

         button_1.addEventListener(MouseEvent.MOUSE_OUT, fl_MouseOutHandler);

}

function fl_AnimateHorizontally_3(event:Event)

{

          if(tape.x < stage.stageWidth){

              tape.x += 10;

          }

}

function fl_MouseOutHandler(event:MouseEvent):void

{

         tape.removeEventListener(Event.ENTER_FRAME, fl_AnimateHorizontally_3);

         button_1.removeEventListener(MouseEvent.MOUSE_OUT, fl_MouseOutHandler);

 

}

button_2.addEventListener(MouseEvent.ROLL_OVER, fl_MouseOverHandler_5);

function fl_MouseOverHandler_5(event:MouseEvent):void

{

         tape.addEventListener(Event.ENTER_FRAME, fl_AnimateHorizontally_5);

         button_2.addEventListener(MouseEvent.MOUSE_OUT, fl_MouseOutHandler_5);

}

function fl_AnimateHorizontally_5(event:Event)

{

         if(tape.x < stage.stageWidth){

              tape.x -= 10;

          }

}

function fl_MouseOutHandler_5(event:MouseEvent):void

{

         tape.removeEventListener(Event.ENTER_FRAME, fl_AnimateHorizontally_5);

         button_2.removeEventListener(MouseEvent.MOUSE_OUT, fl_MouseOutHandler_5);

}

button_ 1 to move the tape forward

button_2 to move the tape backward

Known Participant
April 3, 2013

aslo

the tape has many buttons inside

so the user click to show the picture on the tape

after i use any button on the tape

the button_1 and _2 not working at all

Ned Murphy
Ned MurphyCorrect answer
Legend
April 2, 2013

Do not nest the fl_AnimateHorizontally_3 function inside the fl_MouseOverHandler function, keep it separate from it.

It is not clear what problem you are having when you say "but the tabe across the screen completly !", but here are a few things...

1) You need to assign a starting position when the rollover occurs

2) You need to assign a MOUSE_OUT listener to stop the ENTER_FRAME and reset the tape position

3) You need to put conditions on how far the tape moves before it stops.

button_1.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandler);

function fl_MouseOverHandler(event:MouseEvent):void

{

         tape.x = 0;

         tape.addEventListener(Event.ENTER_FRAME, fl_AnimateHorizontally_3);

         button_1.addEventListener(MouseEvent.MOUSE_OUT, fl_MouseOutHandler);

}

function fl_AnimateHorizontally_3(event:Event)

{

          if(tape.x < stage.stageWidth){

              tape.x += 10;

          }

}

function fl_MouseOutHandler(event:MouseEvent):void

{

         tape.x = 0;

         tape.removeEventListener(Event.ENTER_FRAME, fl_AnimateHorizontally_3);

         button_1.removeEventListener(MouseEvent.MOUSE_OUT, fl_MouseOutHandler);

}

Known Participant
April 2, 2013

perfect thanks

Ned Murphy
Legend
April 2, 2013

You're welcome