[Laszlo-checkins] r13299 - openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9
bargull@openlaszlo.org
bargull at openlaszlo.org
Sun Mar 15 12:49:41 PDT 2009
Author: bargull
Date: 2009-03-15 12:49:38 -0700 (Sun, 15 Mar 2009)
New Revision: 13299
Modified:
openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzMouseKernel.as
openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzSprite.as
Log:
Change 20090315-bargull-SlX by bargull at dell--p4--2-53 on 2009-03-15 19:25:59
in /home/Admin/src/svn/openlaszlo/trunk
for http://svn.openlaszlo.org/openlaszlo/trunk
Summary: fix some cursor issues in swf9
New Features:
Bugs Fixed: LPP-7911 (SWF9: custom cursor issues)
Technical Reviewer: hminsky
QA Reviewer: (pending)
Doc Reviewer: (pending)
Documentation:
Release Notes:
Details:
LzSprite:
- set default context menu also on main application sprite, this is at least required for custom cursors
LzMouseKernel:
- hide custom cursor when mouse leaves screen / context menu is opened
- and redisplay when mouse enters screen again / context menu is closed
- hide custom cursor over selectable TextFields, otherwise the custom cursor and the Flash ibeam cursor at displayed at the same time
Tests:
testcase at bugreport
Modified: openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzMouseKernel.as
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzMouseKernel.as 2009-03-15 19:36:04 UTC (rev 13298)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzMouseKernel.as 2009-03-15 19:49:38 UTC (rev 13299)
@@ -14,16 +14,22 @@
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
+ import flash.text.TextField;
import flash.ui.Mouse;
import flash.ui.MouseCursor;
}#
+ //////////////////
+ // MOUSE EVENTS //
+ //////////////////
+
// sends mouse events to the callback
- static function __sendEvent(view:*, eventname:String) :void {
+ static function __sendEvent (view:*, eventname:String) :void {
if (__callback) __scope[__callback](eventname, view);
//Debug.write('LzMouseKernel event', eventname);
}
+
static var __callback:String = null;
static var __scope:* = null;
static var __lastMouseDown:LzSprite = null;
@@ -54,7 +60,7 @@
}
// Handles global mouse events
- static function __mouseHandler(event:MouseEvent):void {
+ static function __mouseHandler (event:MouseEvent) :void {
var eventname:String = 'on' + event.type.toLowerCase();
if (eventname == 'onmouseup' && __lastMouseDown != null) {
// call mouseup on the sprite that got the last mouse down
@@ -70,7 +76,7 @@
}
// sends mouseup and calls __globalmouseup when the mouse goes up outside the app - see LPP-7724
- static function __mouseUpOutsideHandler():void {
+ static function __mouseUpOutsideHandler () :void {
if (__lastMouseDown != null) {
var ev:MouseEvent = new MouseEvent('mouseup');
__lastMouseDown.__globalmouseup(ev);
@@ -79,15 +85,20 @@
}
// handles MOUSE_LEAVE event
- static function __mouseLeaveHandler(event:Event = null):void {
+ static function __mouseLeaveHandler (event:Event = null) :void {
__mouseLeft = true;
__sendEvent(null, 'onmouseleave');
}
- static function __mouseWheelHandler(event:MouseEvent):void {
+ static function __mouseWheelHandler (event:MouseEvent) :void {
lz.Keys.__mousewheelEvent(event.delta);
}
+
+ //////////////////
+ // MOUSE CURSOR //
+ //////////////////
+
/**
* Shows or hides the hand cursor for all clickable views.
* @param Boolean show: true shows the hand cursor for buttons, false hides it
@@ -158,8 +169,11 @@
cursorSprite.stopDrag();
cursorSprite.visible = false;
LFCApplication.stage.removeEventListener(Event.MOUSE_LEAVE, mouseLeaveHandler);
+ LFCApplication.stage.removeEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
Mouse.show();
} else {
+ // you can only hide the Mouse when Mouse.cursor is AUTO
+ Mouse.cursor = MouseCursor.AUTO;
Mouse.hide();
cursorSprite.x = LFCApplication.stage.mouseX;
cursorSprite.y = LFCApplication.stage.mouseY;
@@ -167,15 +181,47 @@
// respond to mouse move events
cursorSprite.startDrag();
LFCApplication.stage.addEventListener(Event.MOUSE_LEAVE, mouseLeaveHandler);
+ LFCApplication.stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
cursorSprite.visible = true;
}
}
- static function mouseLeaveHandler(evt:Event):void {
+ /**
+ * Triggered when cursor leaves screen or context-menu is opened, in both
+ * cases we must display the system cursor
+ */
+ private static function mouseLeaveHandler (event:Event) :void {
cursorSprite.visible = false;
+ Mouse.show();
+ // use capture-phase because most sprites call stopPropagation() for mouse-events
+ LFCApplication.stage.addEventListener(MouseEvent.MOUSE_OVER, mouseEnterHandler, true);
}
- static function getCursorResource (resource:String):Sprite {
+ /**
+ * Triggered when cursor enters screen or context-menu is closed
+ */
+ private static function mouseEnterHandler (event:Event) :void {
+ cursorSprite.visible = true;
+ Mouse.hide();
+ LFCApplication.stage.removeEventListener(MouseEvent.MOUSE_OVER, mouseEnterHandler, true);
+ }
+
+ /**
+ * Hide custom cursor over selectable TextFields otherwise both the ibeam-cursor
+ * and the custom cursor are displayed
+ */
+ private static function mouseMoveHandler (event:MouseEvent) :void {
+ var target:Object = event.target;
+ if (target is TextField && target.selectable) {
+ cursorSprite.visible = false;
+ Mouse.show();
+ } else {
+ Mouse.hide();
+ cursorSprite.visible = true;
+ }
+ }
+
+ private static function getCursorResource (resource:String) :Sprite {
if (! (LzAsset.isMovieClipAsset(resource) || LzAsset.isMovieClipLoaderAsset(resource))) {
// only swf cursors are supported
return null;
@@ -196,7 +242,6 @@
var asset:Sprite = new assetclass();
asset.scaleX = 1.0;
asset.scaleY = 1.0;
- //Debug.write('cursor asset', asset);
return asset;
}
@@ -211,6 +256,7 @@
cursorSprite.stopDrag();
cursorSprite.visible = false;
LFCApplication.stage.removeEventListener(Event.MOUSE_LEAVE, mouseLeaveHandler);
+ LFCApplication.stage.removeEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
globalCursorResource = null;
Mouse.cursor = MouseCursor.AUTO;
Mouse.show();
@@ -250,6 +296,7 @@
cursorSprite = new Sprite();
cursorSprite.mouseChildren = false;
cursorSprite.mouseEnabled = false;
+ cursorSprite.visible = false;
// Add the cursor DisplayObject to the root sprite
LFCApplication.addChild(cursorSprite);
cursorSprite.x = -10000;
Modified: openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzSprite.as
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzSprite.as 2009-03-15 19:36:04 UTC (rev 13298)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzSprite.as 2009-03-15 19:49:38 UTC (rev 13299)
@@ -42,6 +42,7 @@
import flash.net.URLRequest;
import flash.system.LoaderContext;
import flash.text.TextField;
+ import flash.ui.ContextMenu;
}#
#passthrough {
@@ -1430,7 +1431,7 @@
/* LzSprite.setContextMenu
* Install menu items for the right-mouse-button
- * @param LzContextMenu cmenu: LzContextMenu to install on this view
+ * @param LzContextMenu lzmenu: LzContextMenu to install on this view
*/
function setContextMenu (lzmenu:LzContextMenu) :void {
this.__contextmenu = lzmenu;
@@ -1445,7 +1446,10 @@
// property of MovieClip.prototype, which puts the menu on
// every MovieClip by default. Not sure if there's any way
// to do that in swf9.
- LzSprite.prototype.contextMenu = (lzmenu != null ? lzmenu.kernel.__LZcontextMenu() : null);
+ var cmenu:ContextMenu = (lzmenu != null ? lzmenu.kernel.__LZcontextMenu() : null);
+ LzSprite.prototype.contextMenu = cmenu;
+ // also show the default menu for the main sprite
+ LFCApplication._sprite.contextMenu = cmenu;
}
/**
More information about the Laszlo-checkins
mailing list