1 Reply Latest reply on Nov 16, 2007 6:43 AM by kglad

    How to receive a MouseEvent in other class?

    chrisatflash Level 1
      Can someone tell me what the correct way is to receive a MouseEvent?

      In my example i have made one button class.
      In the class i made a MouseOver, MouseOut and a MouseDown that fire a function.
      This function will do some transition effects.

      In my fla file i have instanciated 2 of these buttons like:

      var button1:ButtonEffect = new ButtonEffect();
      var button2:ButtonEffect = new ButtonEffect();
      button1.x = 50;
      button2.x = 100;
      addChild(button1);
      addChild(button2);

      I also have an MovieClip (a Big Square ) in my library in the Fla file. The identifiers name is "BigSquare"
      Of course i made a class called BigSquare.

      And in my fla i have :
      var BigSQ:BigSquare = new BigSquare();
      BigSQ.x = 200;
      addChid(BigSQ);

      Oke, this works fine. I see two buttons on my Stage and a big Square.

      Now i would like that when i press the first button that the big Square moves something to the left. (onEnterFrame)
      And when pressing the second botton move to the right.

      What is now the correct way to implement this?

      Should i change my code in my button class : addEventListener(MouseEvent.MOUSE_DOWN, goLeft);
      and in the goLeft function write something?

      Or when you press on button one, i could receive this and write something in my BigSquare class?


        • 1. Re: How to receive a MouseEvent in other class?
          kglad Adobe Community Professional & MVP
          any code you use in your button class will effect all buttons you create. so, if you wanted some buttons to do one thing (move bigsquare to the right) and some to do another (move it to the left), you would need to change your class and pass a parameter when you instantiate a button that would indicate whether it's a left-move or right-mover. you would then attach the appropriate listener to the button.

          or you could add listener code in your fla to your button instances, though this would undermine your oop efforts.