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">
                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')) {
                    var dropTarget:LinkBar = LinkBar(event.currentTarget);
                private function dropHandler(event:DragEvent):void {
                  var data:String = event.dragSource.dataForFormat('data').toString();
            <mx:NumberFormatter id="nf" precision="2"/>
            <mx:LinkBar id="lb" dataProvider="{itemsAC}" dragEnter="enterHandler(event);" 
            <mx:HRule width="300" strokeWidth="2"/>
              <mx:Label text="Features books:"/>
              <mx:DataGrid id="booksgrid" dataProvider="{books}" 
                dragEnabled="true" dragMoveEnabled="false" 
                  <mx:DataGridColumn dataField="Author" width="100"/>
                  <mx:DataGridColumn dataField="BookTitle" width="100"/>
                  <mx:DataGridColumn dataField="Price" width="50">
                        <mx:Label text="{outerDocument.nf.format(data.Price)}"/>

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

          Greg Lafrance - Flex 2 and 3 ACE certified


          Flex / AIR Development, Training, and Support Services

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

            It certainly does! thank you for your response