A Flash Developer Resource Site

Results 1 to 11 of 11

Thread: Mac mouse key issue

  1. #1
    Junior Member
    Join Date
    Aug 2004
    Posts
    12

    Mac mouse key issue

    Hi,

    I made a flash object-vr on a pc. I'm using
    Code:
    if (Key.isDown(1)) {...(
    to detect when the left mouse key is pressed to reference the vr's timeline to the mouse position. On a macintosh this is not working however...
    Any idea how I could do this on a mac? And what about 1, 2, 3 button mice and/or trackpads?

    Any clues?

    Thanks for any help,

    Rufus

  2. #2
    Senior Member
    Join Date
    Feb 2005
    Posts
    1,836
    If you copy and past this code in a .fla, it will trace (DOWN -> Code: 83 ACSII: 115 Key: s).
    Code:
    var keyListener:Object = new Object();
    keyListener.onKeyDown = function() {
        trace("DOWN -> Code: "+Key.getCode()+"\tACSII: "+Key.getAscii()+"\tKey: "+chr(Key.getAscii()));
    };
    keyListener.onKeyUp = function() {
        trace("UP -> Code: "+Key.getCode()+"\tACSII: "+Key.getAscii()+"\tKey: "+chr(Key.getAscii()));
    };
    Key.addListener(keyListener);
    If you want to use the mouse then there are functions already in place that you would have to use. Depending on what you want to happen you can use the mouse. There's onMouseDown();
    Example:
    Code:
    mouseListener.onMouseDown = function() {
        this.isDrawing = true;
        this.orig_x = _xmouse;
        this.orig_y = _ymouse;
        this.target_mc = canvas_mc.createEmptyMovieClip("", canvas_mc.getNextHighestDepth());
    };
    There are other ones which you can access through the help menu in flash. It would be in the "ActionScript language Reference"/"ActionScript Classes" and if you go all the way to the M section you would find one that would say mouse. That would give you all you should need to know about the mouse. I don't think that in flash the mouse has an ascii code that can be used. however I've never pursued this and so I don't know if you can use the ascii. I hope that this will help.
    .

  3. #3
    Junior Member
    Join Date
    Aug 2004
    Posts
    12
    Hey Swak,

    Thanks for the lightning fast and deatiled answer. I couldn't find anything really helping me in the language reference.

    Maybe you'll see an answer to my problem if I show you the full code I'm using (if you feel like having a look...)

    Keyframe Actionscript:
    Code:
    this.cursor._visible = false;
    var stageW:Number = 800;
    var stageH:Number = 600;
    function updateCursor() {
    	this.cursor._x = _xmouse;
    	this.cursor._y = _ymouse;
    	if (_xmouse<253 || _xmouse>stageW-19 || _ymouse<74 || _ymouse>stageH-110) {
    		Mouse.show();
    		_root.cursor._visible = false;
    	} else {
    		Mouse.hide();
    		this.cursor._visible = true;
    	}
    	updateAfterEvent();
    }
    Then, on the VR movieclip symbol that contains a serie of bitmaps, I've got this code:
    Code:
    onClipEvent (load) {
    	stop();
    	speed = 5;
    }
    onClipEvent (mouseDown) {
    	if (this.hitTest(_root._xmouse, _root._ymouse, true)) {
    		this._parent.autoPlay.gotoAndStop("los");
    		xRef = _root._xmouse;
    		frameRef = _currentframe;
    	}
    }
    onClipEvent (mouseMove) {
    	if (Key.isDown(1)) {
    		if (this.hitTest(_root._xmouse, _root._ymouse, true)) {
    			var current_x = _xmouse;
    			var difference_x = current_x-prev_x;
    			if (difference_x<0) {
    				this._parent.cursor.gotoAndStop("left");
    			} else if (difference_x>0) {
    				this._parent.cursor.gotoAndStop("right");
    			}
    			prev_x = current_x;
    			frame = (frameRef+Math.floor((_root._xmouse-xRef)/speed))%_totalframes;
    			if (frame<=0) {
    				frame = _totalframes+frame;
    			}
    			gotoAndStop(frame);
    		}
    	}
    }
    onClipEvent (mouseUp) {
    	this._parent.cursor.gotoAndStop("custom");
    }

    If you have any ideas, please let me know...

    Thanks either way,

    Rufus

  4. #4
    Senior Member
    Join Date
    Feb 2005
    Posts
    1,836
    By the look of things, I think all you would have to do is change
    Code:
    if (Key.isDown(1)) {
                    if (this.hitTest(_root._xmouse, _root._ymouse, true)) {
                            var current_x = _xmouse;
                            var difference_x = current_x-prev_x;
                            if (difference_x<0) {
                                    this._parent.cursor.gotoAndStop("left");
                            } else if (difference_x>0) {
                                    this._parent.cursor.gotoAndStop("right");
                            }
                            prev_x = current_x;
                            frame = (frameRef+Math.floor((_root._xmouse-xRef)/speed))%_totalframes;
                            if (frame<=0) {
                                    frame = _totalframes+frame;
                            }
                            gotoAndStop(frame);
                    }
            }
    To
    Code:
    onMouseDown = function() {
                    if (this.hitTest(_root._xmouse, _root._ymouse, true)) {
                            var current_x = _xmouse;
                            var difference_x = current_x-prev_x;
                            if (difference_x<0) {
                                    this._parent.cursor.gotoAndStop("left");
                            } else if (difference_x>0) {
                                    this._parent.cursor.gotoAndStop("right");
                            }
                            prev_x = current_x;
                            frame = (frameRef+Math.floor((_root._xmouse-xRef)/speed))%_totalframes;
                            if (frame<=0) {
                                    frame = _totalframes+frame;
                            }
                            gotoAndStop(frame);
                    }
            }
    You can try this out. There are also others like onMouseMove or onMouseUp or if you want to use the wheel for example:
    Code:
    this.createEmptyMovieClip("line_mc", this.getNextHighestDepth());
    line_mc.lineStyle(2, 0xFF0000, 100);
    line_mc.moveTo(0, 100);
    line_mc.lineTo(0, 0);
    line_mc._x = 200;
    line_mc._y = 200;
    
    var mouseListener:Object = new Object();
    mouseListener.onMouseWheel = function(delta:Number) {
        line_mc._rotation += delta;
    };
    mouseListener.onMouseDown = function() {
        trace("Down");
    };
    Mouse.addListener(mouseListener);
    This code comes from The help section.
    .

  5. #5
    Junior Member
    Join Date
    Aug 2004
    Posts
    12
    Hey Swak,

    Again, thanks for the elaborate answer. The code you suggested seemed logical but didn't work, I think the previous "onClipEvent (mouseDown)" conflicts with the "onMouseDown = function()"...Not sure why yet, but I'm gonna keep trying..

    Thanks for all your help!!

    Rufus

  6. #6
    Senior Member
    Join Date
    Feb 2005
    Posts
    1,836
    Just use this.
    onMouseDown = function() {
    if (this.hitTest(_root._xmouse, _root._ymouse, true)) {
    var current_x = _xmouse;
    var difference_x = current_x-prev_x;
    if (difference_x<0) {
    this._parent.cursor.gotoAndStop("left");
    } else if (difference_x>0) {
    this._parent.cursor.gotoAndStop("right");
    }
    prev_x = current_x;
    frame = (frameRef+Math.floor((_root._xmouse-xRef)/speed))%_totalframes;
    if (frame<=0) {
    frame = _totalframes+frame;
    }
    gotoAndStop(frame);
    }
    }
    I don't think that you need them both.
    .

  7. #7
    Junior Member
    Join Date
    Aug 2004
    Posts
    12
    Hmm, didn't do it...However, I was just trying it like this:
    Code:
    onClipEvent (load) {
    	stop();
    	_global.speed = 5;
    }
    onClipEvent (mouseDown) {
    	if (this.hitTest(_root._xmouse, _root._ymouse, true)) {
    		this._parent.autoPlay.gotoAndStop("los");
    		trace("mouse Down");
    		this.onMouseMove = function() {
    			if (this.hitTest(_root._xmouse, _root._ymouse, true)) {
    				var current_x = _xmouse;
    				var difference_x = current_x-prev_x;
    				if (difference_x<0) {
    					this._parent.cursor.gotoAndStop("left");
    				} else if (difference_x>0) {
    					this._parent.cursor.gotoAndStop("right");
    				}
    				prev_x = current_x;
    				frame = (frameRef+Math.floor((_root._xmouse-xRef)/speed))%_totalframes;
    				if (frame<=0) {
    					frame = _totalframes+frame;
    					xRef = _root._xmouse;
    					frameRef = _currentframe;
    				}
    				gotoAndStop(frame);
    			}
    		};
    	}
    }
    onClipEvent (mouseUp) {
    	trace("mouse Up");
    	this._parent.cursor.gotoAndStop("custom");
    }
    Now I can rotate the object, it works on MAC and PC, BUT when I release the mouse, it doesn't stop rotating anymore...so then I thought I'd add this:
    Code:
    onClipEvent (mouseUp) {
    		stop();
    }
    Of course that also didn't work...I need to find a way now to stop this mouseDown event when the mouse is up...

    Really appreciate all your help!!

    Rufus

  8. #8
    Senior Member
    Join Date
    Feb 2005
    Posts
    1,836
    Why don't you post your .fla and I could try some things with it.
    .

  9. #9
    Junior Member
    Join Date
    Aug 2004
    Posts
    12

    Mac mouse key issue

    I had to put a different image sequence in there, as the original one is work in progress and belongs to the customer...
    I put the original code and the "new" code in there. It's a Flash 8 file.

    If you have the time and feel like trying something with the file, that would be great!

    Thanks for all your efforts so far!!

    PS: I will be gone until Monday, so if I don't respond don't think badly of me ;-)
    Attached Files Attached Files
    • File Type: zip vr.zip (114.0 KB, 117 views)

  10. #10
    Senior Member
    Join Date
    Feb 2005
    Posts
    1,836
    Ok I figured out something.
    use this
    Code:
    this.onPress = function() {
    	g = 1;
    };
    this.onRelease = function() {
    	g = 0;
    };
    this.onDragOut = function() {
    		g = 0;
    };
    //replace if (Key.isDown(1)) { with the code below
    if (g == 1) {
    Enjoy
    .

  11. #11
    Junior Member
    Join Date
    Aug 2004
    Posts
    12
    Hey Swak,

    Perfect!!! Thank you indeed! I had some button symbols floating over the VR, so I had to use what you figured out in a slightly different way, but in the end it worked out just right...

    Thanks again,

    Rufus

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