Author: hqm
Date: 2008-01-13 18:20:02 -0800 (Sun, 13 Jan 2008)
New Revision: 7815

Modified:
   openlaszlo/branches/devildog/WEB-INF/lps/lfc/kernel/swf9/LzSprite.as
   openlaszlo/branches/devildog/WEB-INF/lps/lfc/kernel/swf9/LzTextSprite.as
   openlaszlo/branches/devildog/WEB-INF/lps/lfc/views/LaszloView.js
Log:
Change 20080113-hqm-4 by [EMAIL PROTECTED] on 2008-01-13 21:17:42 EST
    in /cygdrive/c/users/hqm/openlaszlo/devildog/WEB-INF/lps/lfc
    for http://svn.openlaszlo.org/openlaszlo/branches/devildog/WEB-INF/lps/lfc

Summary: use flash.display.SimpleButton for click region in LzSprite

New Features:

Bugs Fixed:

Technical Reviewer: (pending)
QA Reviewer: (pending)
Doc Reviewer: (pending)

Documentation:

Release Notes:

Details:
    
you can designate an abritrary click region using flash.display.SimpleButton.
We probably also want to use this for our button implementation, it handles
over/down/out mouse events by automatically swapping in different 
DisplayObjects.

need to figure out the API for setting conditionally setting the hand cursor
on clickable regions.





Tests:



Modified: openlaszlo/branches/devildog/WEB-INF/lps/lfc/kernel/swf9/LzSprite.as
===================================================================
--- openlaszlo/branches/devildog/WEB-INF/lps/lfc/kernel/swf9/LzSprite.as        
2008-01-13 05:19:45 UTC (rev 7814)
+++ openlaszlo/branches/devildog/WEB-INF/lps/lfc/kernel/swf9/LzSprite.as        
2008-01-14 02:20:02 UTC (rev 7815)
@@ -31,7 +31,8 @@
       public var opacity:Number = 1;
       public var playing:Boolean = false;
       public var clickable:Boolean = false;
-      public var clickbutton:Sprite = null;
+      public var clickbutton:SimpleButton = null;
+      public var clickregion:Shape = null;
       public var masksprite:Sprite = null;
       public var frame:int = 1;
       public var frames:int = 1;
@@ -91,7 +92,7 @@
       */
       public function addChildSprite(sprite:LzSprite):void {
           addChild(sprite);
-          trace('addChildSprite ', sprite, 'added to ' ,this.owner);
+          //trace('addChildSprite ', sprite, 'added to ' ,this.owner);
       }
 
       public function draw():void {
@@ -176,13 +177,13 @@
       }
       
       //// Mouse event trampoline
-      public function attachMouseEvents(spr:Sprite) {
-          spr.addEventListener(MouseEvent.CLICK, handleMouse_CLICK);
-          spr.addEventListener(MouseEvent.DOUBLE_CLICK, 
handleMouse_DOUBLE_CLICK);
-          spr.addEventListener(MouseEvent.MOUSE_DOWN, handleMouse_MOUSE_DOWN);
-          spr.addEventListener(MouseEvent.MOUSE_UP, handleMouse_MOUSE_UP);
-          spr.addEventListener(MouseEvent.MOUSE_OVER, handleMouse_MOUSE_OVER);
-          spr.addEventListener(MouseEvent.MOUSE_OUT, handleMouse_MOUSE_OUT);
+      public function attachMouseEvents(dobj:DisplayObject) {
+          dobj.addEventListener(MouseEvent.CLICK, handleMouse_CLICK);
+          dobj.addEventListener(MouseEvent.DOUBLE_CLICK, 
handleMouse_DOUBLE_CLICK);
+          dobj.addEventListener(MouseEvent.MOUSE_DOWN, handleMouse_MOUSE_DOWN);
+          dobj.addEventListener(MouseEvent.MOUSE_UP, handleMouse_MOUSE_UP);
+          dobj.addEventListener(MouseEvent.MOUSE_OVER, handleMouse_MOUSE_OVER);
+          dobj.addEventListener(MouseEvent.MOUSE_OUT, handleMouse_MOUSE_OUT);
       }
 
       public function handleMouse_CLICK (event:MouseEvent) {
@@ -229,37 +230,38 @@
           o If false, sets the sprite to be unclickable and not receive mouse 
events 
       */
       public function setClickable( c:Boolean ):void {
-          //if (this.clickable == c) return;
+          if (this.clickable == c) return;
           this.clickable = c;
           attachMouseEvents(this);
+          var cb:SimpleButton = this.clickbutton;
+          //trace('sprite setClickable' , c, 'cb',cb);
           if (this.clickable) {
-              var cb:Sprite = this.clickbutton;
+              // TODO [hqm 2008-01] The Flash Sprite docs 
+              // explain how to add a sprite to the tab order using tabEnabled 
property. 
+              this.buttonMode = true;
               if (cb == null) {
-                  this.clickbutton = cb = new Sprite();
-                  cb.alpha = 0;
-                  this.addChild(cb);
-                  attachMouseEvents(cb);
+                  this.clickbutton = cb = new SimpleButton();
+                  addChild(cb);
               }
-              //  TODO [hqm 12-04-2007] This is a sprite with a white
-              // rectangle and alpha=0, to catch mouse clicks. This is
-              // non optimal because the renderer has to process it on
-              // redraws. Maybe bitmap cache could be turned on to
-              // improve performance?
+              cb.useHandCursor = true;
+              var cr = new Shape();
+              this.clickregion = cr;
+              cr.graphics.beginFill(0xffffff);
+              cr.graphics.drawRect(0, 0, 1, 1);
+              cr.graphics.endFill();
+              cr.scaleX = this.lzwidth;
+              cr.scaleY = this.lzheight;
+              // for debugging: make button visible
+              // cb.overState = cr;
               //
-              // The flash docs say there is a fl.controls.Button
-              // class but the compiler can't seem to find it in the
-              // libraries.  There *is* an mx.controls.Button class,
-              // but I haven't figured out how to instantiate it and
-              // am not sure if it is more of a performance drain than
-              // just using this alpha=0 sprite. Not sure we want to
-              // use the higher level flex components lib anyway.
+              cb.hitTestState = cr;
+              attachMouseEvents(cb);
+          } else {
+              this.buttonMode = false;
+              if (cb) {
+                  removeChild(cb);
+              }
 
-
-              cb.graphics.beginFill(0xffffff);
-              cb.graphics.drawRect(this.x, this.y, this.lzwidth, 
this.lzheight);
-              cb.graphics.endFill();
-          } else {
-              this.clickbutton.graphics.clear();
           }
       }
 
@@ -288,9 +290,13 @@
           o Sets the sprite to the specified width 
       */
       public function setWidth( v:* ):void {
+          //trace('sprite setWidth', v);
           this.lzwidth = v;
           // TODO [hqm 2008-01] We need to add back in the code here to
           // update the clipping mask size, and resource stretching as well, 
see swf8 kernel
+          if (this.clickregion != null) {
+              this.clickregion.scaleX = v;
+          }
           draw();
       }
 
@@ -299,9 +305,13 @@
           o Sets the sprite to the specified height 
       */
       public function setHeight( v:* ):void {
+          //trace('sprite setHeight', v);
           this.lzheight = v;
           // TODO [hqm 2008-01] We need to add back in the code here to
           // update the clipping mask size, and resource stretching as well, 
see swf8 kernel
+          if (this.clickregion != null) {
+              this.clickregion.scaleY = v;
+          }
           draw();
       }
 
@@ -381,20 +391,24 @@
           }
       }
 
+      // Create a Flash Sprite to use as the clipping mask.
       public function applyMask():void {
-          if (this.masksprite == null) {
-          var ms:Sprite = this.masksprite = new Sprite();
-              ms.graphics.beginFill(0xffffff);
-              ms.graphics.drawRect(this.x, this.y, this.lzwidth, 
this.lzheight);
-              ms.graphics.endFill();
-              addChild(ms)
+          var ms:Sprite = this.masksprite;
+          if (ms == null) {
+              ms = new Sprite();
           }
-
+          ms.graphics.clear();
+          ms.graphics.beginFill(0xffffff);
+          ms.graphics.drawRect(this.x, this.y, this.lzwidth, this.lzheight);
+          ms.graphics.endFill();
+          addChild(ms);
           this.mask = this.masksprite;
       }
 
       public function removeMask():void {
           this.mask = null;
+          this.removeChild(this.masksprite);
+          this.masksprite == null;
       }
 
 

Modified: 
openlaszlo/branches/devildog/WEB-INF/lps/lfc/kernel/swf9/LzTextSprite.as
===================================================================
--- openlaszlo/branches/devildog/WEB-INF/lps/lfc/kernel/swf9/LzTextSprite.as    
2008-01-13 05:19:45 UTC (rev 7814)
+++ openlaszlo/branches/devildog/WEB-INF/lps/lfc/kernel/swf9/LzTextSprite.as    
2008-01-14 02:20:02 UTC (rev 7815)
@@ -99,10 +99,6 @@
             this.fontname = args.font;
             this.fontsize = args.fontsize;
             this.fontstyle = args.fontstyle;
-            this.__setFormat();
-
-            textclip.htmlText = this.format + this.text + this.closeformat;
-
             textclip.background = false;
 
             // To compute our width:
@@ -142,6 +138,12 @@
             }
             // Default the scrollheight to the visible height.
             this.scrollheight = this.height;
+
+            // TODO [hqm 2008-01] There ought to be only call to
+            // __setFormat during instantiation of an lzText. Figure
+            // out how to suppress the other calls from setters.
+            this.__setFormat();
+
         }
 
         override public function setBGColor( c:* ):void {

Modified: openlaszlo/branches/devildog/WEB-INF/lps/lfc/views/LaszloView.js
===================================================================
--- openlaszlo/branches/devildog/WEB-INF/lps/lfc/views/LaszloView.js    
2008-01-13 05:19:45 UTC (rev 7814)
+++ openlaszlo/branches/devildog/WEB-INF/lps/lfc/views/LaszloView.js    
2008-01-14 02:20:02 UTC (rev 7815)
@@ -254,6 +254,7 @@
   * @access protected
   */
 override function construct ( parent , args) {
+    this.__makeSprite(args);
 
     super.construct( (parent ? parent : canvas), args );
 
@@ -269,8 +270,8 @@
     //this.__LZdepth = ip.__LZsvdepth++;
     //this.__LZsvdepth = 0;
 
-    this.__makeSprite(args);
 
+
     if ( 'width' in args || (('$refs' in args) && ('width' in args.$refs) && 
args.$refs.width) ){
         this.hassetwidth = true;
         this.__LZcheckwidth = false;


_______________________________________________
Laszlo-checkins mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-checkins

Reply via email to