A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: MouseEvent.MOUSE_UP ERROR and problem

  1. #1

    Question MouseEvent.MOUSE_UP ERROR and problem

    I want to create a custom drag button for various reasons.
    I add the event listener MouseEvent.MOUSE_DOWN to call a function which starts a timer to start the drag. This works fine.
    I also added an event listener MouseEvent.Mouse_UP to call a function which stops the dragging function.
    This button only drags along the y access so the mouse will be outside the button and the MouseEvent.MOUSE_UP will not be executed because the mouse is outside the button.
    I would have used an event such which detects mouse_up globally, but none seem to exist.
    I also tried adding the event listener for MOUSE_UP to the stage so it can be globally recognized.
    This was not allowed though as I had aquired an error,"Cannot access a property or method of a null object reference."

    ***
    In summary how would I be able to recognize a mouse up event globally throughout the swf?
    ***

    Thank You,
    TariqM

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    As an example create a movie and place MouseExample as document class. Then create a class with the following script and name it MouseExample.as
    PHP Code:
    package
    {
        
    import flash.display.Sprite;
        
    import flash.events.MouseEvent;
        
    import flash.display.MovieClip;
        public class 
    MouseExample extends MovieClip
        
    {
            public function 
    MouseExample()
            {
                
    this.parent.addEventListener(MouseEvent.MOUSE_DOWNmouseDownHandler);
            }
            private function 
    mouseDownHandler(event:String):void
            
    {
                
    trace("mousedown");
            }
        }

    The mouse will now react to the stage, because this.parent is the stage.
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3

    Question

    I am not using the MovieClip Class for my GUI, but I'm always using the Sprite class. While using the sprite, adding an EventListener to the parent gives me errors.using the root of a sprite also gives me errors. Am I allowed only to add Event Listeners to a MovieClip's parent?

    Help is greatly appreciated!

    Thank You,
    TariqM

  4. #4
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    When you call a document class, the class has to be extended to MovieClip. If it is extended to Sprite you get an error.
    - The right of the People to create Flash movies shall not be infringed. -

  5. #5
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,358
    Document classes can extend Sprite. MovieClip is OK too since MovieClip extends Sprite. Document classes need to be of the type sprite to work at all (meaning extending Sprite or any of its subclasses).

    Adding the MOUSE_UP event to the stage is the correct approach. To access the stage, however, you need to be accessing it from a display object which has been added to a visible display list (or, rather, a display list attached to the stage). So, for example, if you are in the class of the object being dragged, you'll may want to use the added event to detect when the instance has been added to a display list before attempting to set the listener for stage up. You can also (and this would be more reliable since added can be called when added to a display list not attached to the stage) add the stage listener within the MOUSE_DOWN event handler. Then you'll know the sprite is on the stage and will only be adding the MOUSE_UP listener when its needed.

    Check out the Kirupa link in the Resource Thread for some more info (some of the recent posts cover some of this stuff)

  6. #6
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    What you are saying is only partly correct. When you have something in your movie even if it is only this.stop(); or comment lines // you get an error like this when you extend the Sprite class:

    ReferenceError: Error #1065: Variable addFrameScript is not defined.
    at scripts::MenuStarter$iinit()
    You never get an error when you extend the Movieclip class. From therefore I recommend to extend the MovieClip class right from the beginning.
    Last edited by cancerinform; 09-05-2006 at 03:04 AM.
    - The right of the People to create Flash movies shall not be infringed. -

  7. #7
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,358
    That doesn't make it partly correct. It just means that if you want to use a feature Sprites don't support and MovieClips do (frames) then you'll want to extend MovieClip. You could just as easily say MovieClip is also partly correct because it doesn't have a currentState property and the UIComponent class does.

    Either way, your document class needs to extend at least Sprite.

  8. #8
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    Ok, I have attached an example, where you have mousevents for the stage (up and down) and a separate mouseevent for a button (up and down) with a drag event. All you need to do is remove the mouseevent for the stage, since there is eventbubbling. You don't need the Sprite class for that.


    Quote Originally Posted by senocular
    ...if you want to use a feature Sprites don't support and MovieClips do (frames) then you'll want to extend MovieClip.
    Well, there is only one frame and I wanted a comment. How could I otherwise do that, if I have to extend the Sprite class in my script. Doesn't make sense to me.
    Attached Files Attached Files
    - The right of the People to create Flash movies shall not be infringed. -

  9. #9
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,358
    then you would extend MovieClip

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