Download presentation
Presentation is loading. Please wait.
Published byLenard Day Modified over 9 years ago
1
Mouse Events & Keyboard Inputs Flash ActionScript Introduction to Thomas Lövgren thomas.lovgren@humlab.umu.se
2
Mouse Events & methods The movieClips keep track of mouse position through the properties _xmouse and _ymouse The movieClips keep track of mouse position through the properties _xmouse and _ymouse trace("xMouse:" + _root._xmouse + " yMouse:" + _root._ymouse); Show Mouse cursor Show Mouse cursorMouse.show(); Hide Mouse cursor Hide Mouse cursorMouse.hide();
3
Mouse Events & methods In order to catch Mouse events an event listener must be created In order to catch Mouse events an event listener must be created Mouse events: Mouse events: onMouseDown onMouseUp onMouseMove onMouseWheel //get mouse position _root.onMouseMove = function(){ xMouse = _xmouse; yMouse = _ymouse; }
4
Mouse Event Listener Mouse events can be caught by event handlers Mouse events can be caught by event handlers Example: create an Event Listener for the Mouse Example: create an Event Listener for the Mouse Step 1: create an Object Step 2: create an event handler Step 3: call addListener() var mouseListener:Object = new Object(); mouseListener.onMouseDown = function():Void{ trace("Mouse down"); }Mouse.addListener(mouseListener);
5
Drag & drop Drag and drop a movieClip with the mouse (left click) Drag and drop a movieClip with the mouse (left click) //click/drag the circle circle_mc.onPress = function(){ //startDrag(target, lockcenter, left, top, right, bottom) startDrag(this, false, 25, 25, 500, 375); } //release the circle circle_mc.onRelease = circle_mc.onReleaseOutside = function(){ this.stopDrag(); //stop drag }
6
Hitdetection The hitTest() method could be used for hitdetection between movieClips The hitTest() method could be used for hitdetection between movieClips //check detection if (circle_mc.hitTest(square_mc)){ hit_txt.text = "Hit!" }else{ hit_txt.text = "Not hit!" }
7
Keyboard Inputs Why Use Keyboard Input? Why Use Keyboard Input? One big reason is accessibility (navigation, forms, games etc) Many computer users are very accustomed to using the Enter (Return) key for a variety of things var keyListener:Object = new Object(); keyListener.onKeyDown = function() { //check if Enter key is pressed if (Key.isDown(Key.ENTER)){ keyOutput = "Enter press"; //trace ("Virtual key code: "+Key.getCode()+" (ENTER key)"); }} Key.addListener(keyListener); // add the listener
8
Keyboard Inputs Navigation example: Navigation example: Using the Arrow keys to navigate var KeyListener:Object = new Object(); KeyListener.onKeyDown = function():Void { if(Key.isDown(Key.LEFT)){ _root.sections.gotoAndStop(“sound”); //goto sound section }Key.addListener(KeyListener);
9
Keyboard & Usability Example using tabs and the setFocus function Example using tabs and the setFocus function //set focus on text field Selection.setFocus(name_txt); //set up the tab index name_txt.tabIndex = 1; city_txt.tabIndex = 2; email_txt.tabIndex = 3; send_btn.tabIndex = 4;
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.