6 Replies Latest reply on May 26, 2009 12:39 PM by Flex harUI

    ItemRenderer and drag and dropping...

    rckehoe Level 1

      I have two mx:list controls.... Both use the ItemRender functionality to display custom data in the list...

       

      ListA and ListB

       

      I enabled the dragging and dropping functionaity between the two list boxes and this works as expected...

       

      When I used the dragDrop funtion on ListB, I am calling a function that looks like this...

       

      private function UpdateSelectedDirs(event:DragEvent):void {

       

                /// Data Here

       

      }

       

      How do I obtain the information from the selected object that was dragged?

      The ItemRender defines a field called title and another field called path...

       

      Is there any way to access this information when the object is dragged from ListA and dropped into ListB?

       

      I tried this with no luck:

      var ObjectPath:String = event.dragSource.dataForFormat('path') as String;

       

      Should that work for me?

        • 1. Re: ItemRenderer and drag and dropping...
          Flex harUI Adobe Employee

          I'd try:

               event.dragInitiator.selectedItem.path

           

          This might also work:

           

          var ObjectPath:String = event.dragSource.dataForFormat("items").path as String;

           

          Alex Harui

          Flex SDK Developer

          Adobe Systems Inc.

          Blog: http://blogs.adobe.com/aharui

          • 2. Re: ItemRenderer and drag and dropping...
            rckehoe Level 1

            Neither of the 2 worked for me....

             

            This produced an error for me...

             

            event.dragInitiator.selectedItem.path

            I belive it's because the selectedItem resource is not able to be called with event:DragEvent as the handler.

             

            Any other options?

            • 3. Re: ItemRenderer and drag and dropping...
              Flex harUI Adobe Employee

              Well, that's the correct general principle but the actual code will depend on your circumstances, such as:

               

              - What do your dataProvider items look like?  Regular objects or instances of classes?

              - Did you get an exception dialog or nothing?  If you got an exception post the full stacktrace

               

              You can do some diagnostics by adding a Label that binds to the source List's selectedItem and/or its .path property so you can see what the source List thinks is selected, if anything.

               

              Alex Harui

              Flex SDK Developer

              Adobe Systems Inc.

              Blog: http://blogs.adobe.com/aharui

              • 4. Re: ItemRenderer and drag and dropping...
                rckehoe Level 1

                This is the erro that I get when I use:

                var Path:String = event.dragInitiator.selectedItem.path;

                 

                The error is:

                1119: Access of possibly undefined property selectedItem through a reference with static type mx.core:IUIComponent.

                 

                 

                The whole function looks like this:

                 

                private function UpdateSelectedDirs(event:DragEvent):void {

                        var Path:String = event.dragInitiator.selectedItem.path;
                        trace(Path);
                }

                 

                I have 2 mx:lists that look like this:

                 

                <mx:List x="0" y="48" width="361" height="220" itemRenderer="FTP_Listing_ItemRender" id="DIRLIST_PATH" dragEnabled="true">
                     <mx:dataProvider>{_SERV_GetDirectoryListing.lastResult.root.directory}</mx:dataProvider>
                </mx:List>

                 

                <mx:List x="369" y="48" width="212" height="220" id="backup_list" dropEnabled="true" itemRenderer="FTP_Listing_ItemRender" dragDrop="UpdateSelectedDirs(event);"></mx:List>

                 

                I have an httpservice that gets an XML document with information and populates the first List box as you can tell.

                 

                Now what am I doing wrong?

                • 5. Re: ItemRenderer and drag and dropping...
                  rckehoe Level 1

                  In case anyone is interested... If found out a solution to my problem...

                   

                  Here is the code that I used:

                   

                  var ObjArray:Array = event.dragSource.dataForFormat('items') as Array;
                  var Path:String = ObjArray[0].path;
                         
                  Alert.show(Path);

                  • 6. Re: ItemRenderer and drag and dropping...
                    Flex harUI Adobe Employee

                    Ah, yes.  I would try this:

                     

                    var Path:String = List(event.dragInitiator).selectedItem.path;

                     

                    Make sure you import mx.controls.List in your script block.

                     

                    Alex Harui

                    Flex SDK Developer

                    Adobe Systems Inc.

                    Blog: http://blogs.adobe.com/aharui