Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
0

how to animate a mc by button in over state

New Here ,
Apr 02, 2013 Apr 02, 2013

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 !

TOPICS
ActionScript
1.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Apr 02, 2013 Apr 02, 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.addEventList

...
Translate
LEGEND ,
Apr 02, 2013 Apr 02, 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);

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 02, 2013 Apr 02, 2013

perfect thanks

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 02, 2013 Apr 02, 2013

You're welcome

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 03, 2013 Apr 03, 2013

sorry but

i got this error

Cannot access a property or method of a null object reference.

          at Untitled_fla::MainTimeline/fl_MouseOutHandler()

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Apr 03, 2013 Apr 03, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 03, 2013 Apr 03, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 03, 2013 Apr 03, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 03, 2013 Apr 03, 2013

The 1009 error indicates that one of the objects being targeted by your code is out of scope.  This could mean that the object....

 

- is declared but not instantiated

- doesn't have an instance name (or the instance name is mispelled)

- does not exist in the frame where that code is trying to talk to it

- is animated into place but is not assigned instance names in every keyframe for it

- is one of two or more consecutive keyframes of the same objects with no name assigned in the preceding frame(s).

 

If you go into your Publish Settings Flash section and select the option to Permit debugging, your error message should have a line number following the frame number which will help you isolate which object is involved.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 03, 2013 Apr 03, 2013

thats after premitt de

Cannot access a property or method of a null object reference.

          at Untitled_fla::MainTimeline/fl_MouseOutHandler()[Untitled_fla.MainTimeline::frame1:23]

and thats from debug movie

         button_2.removeEventListener(MouseEvent.MOUSE_OUT, fl_MouseOutHandler_5);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 03, 2013 Apr 03, 2013

its weird

every time i got the same msg

with different frame Number

its somthing related to the mouse out event

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 03, 2013 Apr 03, 2013

the mouse out event on button _2 is the problem

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 03, 2013 Apr 03, 2013
LATEST

SOOOOOLVED

thnx so much for help

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines