[Laszlo-checkins] r12477 - in openlaszlo/trunk/WEB-INF/lps/lfc: kernel/swf9 views

bargull@openlaszlo.org bargull at openlaszlo.org
Wed Jan 14 13:53:31 PST 2009


Author: bargull
Date: 2009-01-14 13:53:27 -0800 (Wed, 14 Jan 2009)
New Revision: 12477

Modified:
   openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzSprite.as
   openlaszlo/trunk/WEB-INF/lps/lfc/views/LaszloView.lzs
Log:
Change 20090114-bargull-vzc by bargull at dell--p4--2-53 on 2009-01-14 17:31:20
    in /home/Admin/src/svn/openlaszlo/trunk
    for http://svn.openlaszlo.org/openlaszlo/trunk

Summary: fix z-order bug in swf9

New Features:

Bugs Fixed: LPP-7628

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

Documentation:

Release Notes:

Details:
The original z-order needs to be taken into account before the new z-order is applied, as it's described in the docs for "setChildIndex()":
---
When you use the setChildIndex() method and specify an index position that is already occupied, the only positions that change are those in between the display object's former and new position. All others will stay the same. If a child is moved to an index LOWER than its current index, all children in between will INCREASE by 1 for their index reference. If a child is moved to an index HIGHER than its current index, all children in between will DECREASE by 1 for their index reference.
---
Also added a try-catch block in case a null-ptr or an invalid sprite was supplied.
    

Tests:
testcases at LPP-7628 and LPP-7321



Modified: openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzSprite.as
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzSprite.as	2009-01-14 20:54:07 UTC (rev 12476)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf9/LzSprite.as	2009-01-14 21:53:27 UTC (rev 12477)
@@ -1245,24 +1245,41 @@
 
       /**
         * Puts this sprite in front of one of its siblings.
-        * @param LzSprite v: The sprite this sprite should go in front of. If the passed sprite is null or not a sibling, the method has no effect.
+        * @param LzSprite v: The sprite this sprite should go in front of.
+        * If the passed sprite is null or not a sibling, the method has no effect.
         */
-      public function sendInFrontOf( sprite ){
+      public function sendInFrontOf (targetSprite:LzSprite) :void {
           if (!this.isroot) {
-              var i = parent.getChildIndex(sprite);
-              var j = parent.getChildIndex(this);
-              if (j < i) parent.setChildIndex(this, i);
+              try {
+                  // @devnote "http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/display/DisplayObjectContainer.html#setChildIndex()"
+                  // > If a child is moved to an index LOWER than its current index,
+                  // > all children in between will INCREASE by 1 for their index reference.
+                  var myDepth:int = parent.getChildIndex(this);
+                  var targetDepth:int = parent.getChildIndex(targetSprite);
+                  parent.setChildIndex(this, myDepth < targetDepth ? targetDepth : targetDepth + 1);
+              } catch (e:Error) {
+                  // if targetSprite isn't a child of the DisplayObjectContainer
+              }
           }
       }
 
       /** sendBehind()
         * Puts this sprite behind one of its siblings.
-        * @param LzSprite sprite: The sprite this sprite should go in front of. If the sprite is null or not a sibling, the method has no effect.
+        * @param LzSprite sprite: The sprite this sprite should go in front of.
+        * If the sprite is null or not a sibling, the method has no effect.
       */
-      public function sendBehind( sprite ){
+      public function sendBehind (targetSprite:LzSprite) :void {
           if (!this.isroot) {
-              var i = parent.getChildIndex(sprite);
-              parent.setChildIndex(this, i);
+              try {
+                  // @devnote "http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/display/DisplayObjectContainer.html#setChildIndex()"
+                  // > If a child is moved to an index HIGHER than its current index,
+                  // > all children in between will DECREASE by 1 for their index reference.
+                  var myDepth:int = parent.getChildIndex(this);
+                  var targetDepth:int = parent.getChildIndex(targetSprite);
+                  parent.setChildIndex(this, myDepth > targetDepth ? targetDepth : targetDepth - 1);
+              } catch (e:Error) {
+                  // if targetSprite isn't a child of the DisplayObjectContainer
+              }
           }
       }
 

Modified: openlaszlo/trunk/WEB-INF/lps/lfc/views/LaszloView.lzs
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/views/LaszloView.lzs	2009-01-14 20:54:07 UTC (rev 12476)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/views/LaszloView.lzs	2009-01-14 21:53:27 UTC (rev 12477)
@@ -2626,13 +2626,10 @@
   * This method makes this view the frontmost subview of this view's parent.
   * */
 function bringToFront ( ){
-    //this is really a function of the parent view
-    //this.immediateparent.changeOrder ( this , 1);
-
     // FIXME: [hqm 2006-09] in some cases I have seen this.sprite unbound, is that ever OK?
     if (!this.sprite) {
         if ($debug) {
-            Debug.write("no sprite on ",this);
+            Debug.warn("no sprite on ",this);
         }
         return;
     }
@@ -2665,31 +2662,35 @@
    var az = a.sprite.getZ();
    var bz = b.sprite.getZ();
    if (az < bz)
-      return -1
+      return -1;
    if (az > bz)
-      return 1
-   return 0
+      return 1;
+   return 0;
 }
 
 /**
-  * Puts this view behind one of its siblings.
-  * @param LzView v: The view this view should go in front of. If the passed 
+  * Puts this view directly behind one of its siblings. If this view is
+  * already in back of the target, but there are other views between this
+  * view and the target, that means this view will be moved in front of the
+  * intervening views.
+  * @param LzView v: The view this view should go behind. If the passed
   * view is null or not a sibling, the method has no effect.
   * @return Boolean: Method returns true if the operation is successful.
   */
 function sendBehind ( v ){
-    //return this.immediateparent.changeOrder( this, -1, v , false );
     return (v ? this.sprite.sendBehind(v.sprite) : false);
 }
 
 /**
-  * Puts this view in front of one of its siblings.
-  * @param LzView v: The view this view should go in front of. If the passed 
+  * Puts this view directly in front of one of its siblings. If this view is
+  * already in front of the target, but there are other views between this
+  * view and the target, that means this view will be moved in back of the
+  * intervening views.
+  * @param LzView v: The view this view should go in front of. If the passed
   * view is null or not a sibling, the method has no effect.
   * @return Boolean: Method returns true if the operation is successful.
   */
 function sendInFrontOf ( v ){
-    //return this.immediateparent.changeOrder( this, 1, v , true );
     return (v ? this.sprite.sendInFrontOf(v.sprite) : false);
 }
 
@@ -2697,8 +2698,6 @@
   * This method makes this view the hindmost subview of this view's parent.
   */
 function sendToBack ( ){
-    //this is really a function of the parent view
-    //this.immediateparent.changeOrder ( this , -1);
     this.sprite.sendToBack();
 }
 



More information about the Laszlo-checkins mailing list