A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: I need to know when an instance of a class is clicked

  1. #1
    Junior Member
    Join Date
    Nov 2013
    Posts
    12

    I need to know when an instance of a class is clicked

    I know how to do this if the object to be clicked isn't an instance of a class i.e.:

    missile.addEventListener(MouseEvent.MOUSE_DOWN, mouseDown);
    But what do I do if "missile" is a class object? Using above code I get an error because when the project is opened there aren't any instances of it to begin with. What changes do I make to above line and should it go in the main code or in the missile class code?

    I also tried the below line in the class code for "missile" class but again it didn't work.

    this.addEventListener(MouseEvent.MOUSE_DOWN, mouseDown);

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    I'm not sure what you mean, attach your files or a rough mock up

  3. #3
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    If you mean calling it from the library when its not on the stage, then something like so

    PHP Code:
    import flash.events.MouseEvent;

    var 
    missil:missile = new missile();
    addChild(missil);
    missil.50;
    missil.50;
    missil.buttonMode true;
    missil.addEventListener(MouseEvent.MOUSE_DOWNmouseIsDown);

    function 
    mouseIsDown(e:MouseEvent):void
    {
        
    trace(e.target);


  4. #4
    Junior Member
    Join Date
    Nov 2013
    Posts
    12
    I didn't explain it well but I found out the solution but thanks anyway. I put the following line in the constructor code for the missile class:

    addEventListener(MouseEvent.MOUSE_DOWN, clickHandler);

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