I am making a game with as3. I have a Mian Class.In its main function i am putting a movieClip stored in a variable named btn and attaching an EventListener to it for CLICK which envokes a function named StartGame. To test it in the function i am using a statement that fades a movieClip holed in a variable bgClip.But its not working. Dont know why.Although it is not showing any error

package  {
import flash.display.Stage;
import flash.display.StageDisplayState;
import flash.display.Sprite;
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
    public class Main extends MovieClip {
    public var btn:startbtn = new startbtn();
    public var bgClip:menuBg = new menuBg();
    public function Main() {
      bgClip.x = bgClip.y = 0;
      btn.addEventListener(MouseEvent.CLICK , startGame);           
      private function startGame(e:MouseEvent):void {
         bgClip.alpha = 0.5;
  • \$\begingroup\$ Which part is working? Do the button and bg show up? What happens if you add the event listener to the stage? \$\endgroup\$ – AturSams Apr 30 '14 at 22:10
  • \$\begingroup\$ @ArthurWulfWhite button and bg shows up but button does not become a button even it does not show a hand cursor when i put my mouse on it and when i click it just nothing happens it looks like we cant assign an eventlistener to a variable holding a movieClip(If i am not wrong) \$\endgroup\$ – user3536228 May 1 '14 at 4:40
  • \$\begingroup\$ Is this your entire application? Are you publishing using Flash Professional? (Ie, not FlashDevelop etc...) \$\endgroup\$ – null May 1 '14 at 11:38
  • \$\begingroup\$ problem solved but i dont know why \$\endgroup\$ – user3536228 May 5 '14 at 1:51

Your code looks fine to me. Adding a MouseEvent listener to a display object on the stage should work as intended. Try adding this line after adding the button:


If the result is not "2" then it would suggest that there is some other object on the stage that is blocking the cursor from hitting the button.

Common situations where this happens is when you have a large textfield that covers a button, or some other large transparent object (or a visible object with a transparent area).

If there really are no other objects on the stage then something more obscure is happening. Try making a new MovieClip that is just a coloured rectangle and try attaching the MouseEvent listener to that, without anything else on the stage.

I am guessing you are publishing your game using Flash Professional, which can complicate things by giving you an environment outside the code where you can change the settings and contents of the stage. Try making a brand new project and see if the problem persists there.

Good luck :)

| improve this answer | |
  • \$\begingroup\$ problem solved but i dont know why \$\endgroup\$ – user3536228 May 5 '14 at 1:52

Not the answer you're looking for? Browse other questions tagged or ask your own question.