2 Replies Latest reply on Feb 19, 2010 7:49 AM by JockMahon

    drop to a linkbar

    JockMahon Level 1

      Is it possible to drop a drag

      operation onto a link bar say from a grid, i taught i might be able to

      sub class the linkbar and implement a interface but looks like it's the ListBase that

      controls all this stuff

        • 1. Re: drop to a linkbar
          Gregory Lafrance Level 6

          This code answers your question:

           

          <?xml version="1.0"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
            <mx:Script>
              <![CDATA[
                import mx.controls.Label;        
                import mx.core.DragSource;
                import mx.managers.DragManager;
                import mx.events.*;
                import mx.collections.ArrayCollection;
                import mx.controls.LinkBar;
                [Bindable] private var books:ArrayCollection =  new ArrayCollection([
                    {Author:'Samuel Phillips', BookTitle:'Winter in Tahoe', Price:28.00},
                    {Author:'Robert McGaven', BookTitle:'Southwest Sunrise', Price:18.00},
                    {Author:'Linda Thomas', BookTitle:'Lilies on the Pond', Price:19.50},
                    {Author:'Richard Avondale', BookTitle:'Misty Morning', Price:32.00}
                  ]);
                [Bindable] private var cartbooks:ArrayCollection =  new ArrayCollection();
                [Bindable] private var itemsAC:ArrayCollection =  new ArrayCollection(["Drag Here"]);
          
                private function mouseDownHandler(event:MouseEvent):void {
                  var dragInitiator:DataGrid = DataGrid(event.currentTarget);
                  var dragData:String = dragInitiator.selectedItem.BookTitle;
                  var dragSource:DragSource = new DragSource();
                  dragSource.addData(dragData, 'data');
                  var proxyObj:Label = new Label();
                  proxyObj.text = dragInitiator.selectedItem.BookTitle;
                  DragManager.doDrag(dragInitiator, dragSource, event, proxyObj, -20, -20);
                }
                private function enterHandler(event:DragEvent):void {
                  if (event.dragSource.hasFormat('data')) {
                    DragManager.showFeedback(DragManager.COPY);
                    var dropTarget:LinkBar = LinkBar(event.currentTarget);
                    DragManager.acceptDragDrop(dropTarget);
                  }
                }
                private function dropHandler(event:DragEvent):void {
                  var data:String = event.dragSource.dataForFormat('data').toString();
                  if(!itemsAC.contains(data)){
                    itemsAC.addItem(data);
                  }
                }    
              ]]>
            </mx:Script>
            <mx:NumberFormatter id="nf" precision="2"/>
            <mx:LinkBar id="lb" dataProvider="{itemsAC}" dragEnter="enterHandler(event);" 
              dragDrop="dropHandler(event);"/>
            <mx:HRule width="300" strokeWidth="2"/>
            <mx:VBox>
              <mx:Label text="Features books:"/>
              <mx:DataGrid id="booksgrid" dataProvider="{books}" 
                dragEnabled="true" dragMoveEnabled="false" 
                mouseDown="mouseDownHandler(event);">                
                <mx:columns>
                  <mx:DataGridColumn dataField="Author" width="100"/>
                  <mx:DataGridColumn dataField="BookTitle" width="100"/>
                  <mx:DataGridColumn dataField="Price" width="50">
                    <mx:itemRenderer>
                      <mx:Component>
                        <mx:Label text="{outerDocument.nf.format(data.Price)}"/>
                      </mx:Component>
                    </mx:itemRenderer>
                  </mx:DataGridColumn>
                </mx:columns>    
              </mx:DataGrid>
            </mx:VBox>
          </mx:Application>
          


          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

          • 2. Re: drop to a linkbar
            JockMahon Level 1

            It certainly does! thank you for your response