dcsimg
A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: right click in as3 WITHOUT context menu

  1. #1
    Senior Member
    Join Date
    Oct 2009
    Posts
    112

    right click in as3 WITHOUT context menu

    does anyone know how to make right clicking work in as3?

    i don't want a context menu to appear, i just want it to work as an EventListener for MovieClips.

    For example, imagine that RIGHT_CLICK is a MouseEvent, it would look like this:
    Code:
    myButton.addEventListener(MouseEvent.RIGHT_CLICK, rightClicked);
    function rightClicked(e:MouseEvent):void{
          my function in here);
    }
    any ideas? i know the code wont end up looking like this, but does anyone know how to pull off this same idea using a right click?

    i also saw somtehing like this:
    Code:
    myButton.addEventListener(MouseEvent.buttonDown, rightClicked);
    function rightClicked(e:MouseEvent):void{
         if(return=false){
             (my function in here);
    }
    but its not currently working properly

  2. #2
    Junior Member
    Join Date
    Jan 2009
    Posts
    11
    I don't know of any way except when embedded within HTML. And in that case, you use JavaScript to stop the right click from hitting the SWF and then tell the SWF via ExternalInterface that a right click has occured.

    This guy has a working example up: http://www.uza.lt/blog/2007/08/solve...-click-in-as3/

  3. #3
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    Uza's example is the best option out there right now - however you need to be aware that it doesn't work in all browsers - notably webkit based browsers (eg. safari). Not sure about chromium.
    Please use [php] or [code] tags, and mark your threads resolved 8)

  4. #4
    Senior Member
    Join Date
    Oct 2009
    Posts
    112
    does neone know what this means?

    Code:
    if(my> 0 && my <stage.stageHeight && mx> 0 && mx <stage.stageWidth

  5. #5
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    It's checking whether mx and my are within the bounds of the stage - I'm guessing those are mouse coordinates...
    Please use [php] or [code] tags, and mark your threads resolved 8)

  6. #6
    Junior Member
    Join Date
    Jan 2009
    Posts
    11
    Quote Originally Posted by neznein9 View Post
    It's checking whether mx and my are within the bounds of the stage - I'm guessing those are mouse coordinates...
    Yep. Just prior to that if statement, these lines appear:
    Code:
    var mx:int = stage.mouseX;
    var my:int = stage.mouseY;

  7. #7
    Senior Member
    Join Date
    Oct 2009
    Posts
    112
    alright that makes sense i just cant see where there would be an event listener added to a movie clip....
    obviously im not understanding this...i want to add an event listener to a movieclip that will trigger a function when right clicked.
    ill have another go at it and let the forum know how it goes

  8. #8
    Senior Member
    Join Date
    Oct 2009
    Posts
    112
    for some reason i keep gettin the error that theres extra characters at the end of this code but im sucre theres not...
    Code:
    import flash.display.*;
    import flash.external.ExternalInterface;
     
    RightClick extends Sprite
    {
          
    function RightClick()
        {
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align = StageAlign.TOP_LEFT;
              
            var methodName:String = "rightClick";
            var method:Function = onRightClick;
            ExternalInterface.addCallback(methodName, method);
        }
          
    function onRightClick():void {
            var mx:int = stage.mouseX;
            var my:int = stage.mouseY;
           if(my> 0 && my <stage.stageHeight && mx> 0 && mx <stage.stageWidth) {
                trace("mastButton"+" was rightCLICKED");
        }
    }
    if nething theres not enough

    what does rightClick extends sprite mean? is that supposed to be left in?
    Last edited by mattwatts15; 11-18-2009 at 06:20 PM.

  9. #9
    Senior Member
    Join Date
    Oct 2009
    Posts
    112
    if this is the code:
    Code:
    import flash.display.*;
    import flash.external.ExternalInterface;
    
      
    function RightClick()
        {
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align = StageAlign.TOP_LEFT;
              
            var methodName:String = "rightClick";
            var method:Function = onRightClick;
            ExternalInterface.addCallback(methodName, method);
        }
          
    function onRightClick():void {
            var mx:int = stage.mouseX;
            var my:int = stage.mouseY;
           if(my> 0 && my <stage.stageHeight && mx> 0 && mx <stage.stageWidth) {
                trace("mastButton"+" was rightCLICKED");
        }
    }
    then where do i tell it that i want to have the MouseEvent EventListener on my movieclip labeled "mastButton" ??
    (obviously i know its not really a MouseEvent but u know what i mean)

Tags for this Thread

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