4 Replies Latest reply on Mar 30, 2011 8:49 AM by elrobis

    BoxDivider does not seem to report proper X position when it is dragged, anybody know why?

    Forkol

      I'm trying to get the X-position of DividedBox's BoxDivider.

       

      I am using this to get (inside of a Divider Event handler for the DIVIDER_DRAG)

       

      myVBoxDivider = (myBox.getDividerAt(0));

       

       

       

      // save the divider's position to later snap-back to it

      lastPos = myVBoxDivider.x;

       

      trace("X = " + lastPos);

       

      However, lastPos does not update correctly when the divider is 'dragged'.  It will update when you click it initially, but not when dragged.

      But, the x-position seems to be correctly updated while dragging if you use the myVBoxDivider.contentMouseX or myVBoxDivider.MouseX, but then it seems to report 'relative delta' movement rather than a true-x position in the content space.

       

      This seems like a bug.  I'm thinking I could work around it by getting the MouseX and converting it maybe back to Local Space, but before I go about trying that, I'd thought I'd get some advice about what I may be possibly doing wrong or some other way of implementing this.

       

      What I'm really trying to do is change the behavior of a DividedBox so that 'double-click' will set the BoxDivider at minimum, and a second 'double click' will move it back to where it was last dragged (or located initially),  If someone knows of code or code example that would work, I would really appreciate the reference.

       

      Thanks,

       

      Michael

        • 1. Re: BoxDivider does not seem to report proper X position when it is dragged, anybody know why?
          Gregory Lafrance Level 6

          This should answer your question.

           

          If this post answers your question or helps, please mark it as such.


          Greg Lafrance - Flex 2 and 3 ACE certified

          www.ChikaraDev.com

          Flex / AIR Development, Training, and Support Services

           

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
            width="100%" height="100%"
            backgroundColor="0x8A9DE2" backgroundGradientColors="[0x8A9DE2, 0x8A9DE2]"
            paddingBottom="0" paddingLeft="0" paddingRight="0" paddingTop="0"
            creationComplete="init();">
            <mx:Script>
              <![CDATA[
                import mx.events.FlexEvent;
                private var divLoc:int;
                
                private function init():void {
                  divLoc = 0;
                  hdvbx.getDividerAt(0).addEventListener(MouseEvent.DOUBLE_CLICK, handleDoubleClick);
                }
                private function handleDoubleClick(e:MouseEvent):void {
                  if (divLoc > 0) {
                    hdvbx.getDividerAt(0).x = divLoc;
                    divLoc = 0;
                  }
                  else {
                    divLoc = hdvbx.getDividerAt(0).x;
                    hdvbx.getDividerAt(0).x = 0;
                  }
                }      
              ]]>
            </mx:Script>  
            <mx:HDividedBox id="hdvbx" backgroundColor="0x4242D3" width="100%" height="100%"    
              liveDragging="true" doubleClickEnabled="true" 
              dividerAffordance="10" horizontalGap="15">
              <mx:VBox width="25%" height="100%" backgroundColor="0xFF0000"/>
              <mx:VBox width="75%" height="100%" backgroundColor="0x0000FF"/>
            </mx:HDividedBox>
          </mx:Application>
          
          1 person found this helpful
          • 2. Re: BoxDivider does not seem to report proper X position when it is dragged, anybody know why?
            Forkol Level 1

            I pretty much had the same thing, but I had added an additional event processor for drag events, which it looks like I didn't need.  Anyway, yours works great!  Thank You!

            • 3. Re: BoxDivider does not seem to report proper X position when it is dragged, anybody know why?
              Forkol Level 1

              And the reason why mine did not work is I did my addEventListener() in a class constructor that derived from DividedBox.  Apparently, any addEventListener needs to be done when the entire widget is already created and laid out.  Hm, that's something to keep in mind for the future.

              • 4. Re: BoxDivider does not seem to report proper X position when it is dragged, anybody know why?
                elrobis

                Just FYI for others who come across this --it seems setting liveDragging="true" on the DividedBox is essential for the BoxDivider to catch the doubleclick event.  I was confused why my nearly equal implementation wasn't working, then I noticed that property set in Gregory's example.  Thanks Gregory /E