title: Stop List From Scrolling
body: <p>I have a datagrid that's using a custom itemrender with a button in it. I have a problem whereby when I click on a button the datagrid list scrolls its self. How can I prevent this behaviour?</p>
  
  <p><strong>Extended datagrid</strong></p>
  
  <pre><code>&lt;mx:DataGrid xmlns:mx="http://www.adobe.com/2006/mxml"
               doubleClickEnabled="false"
               alternatingItemColors="[#ffffff, #f1f1f1]"
               mouseDown="mdhandler(event)"
               sortableColumns="true"
               xmlns:datagrids="components.content.contents.datagrids.*"
               creationComplete="_creationcomplete(event)"&gt;
  
      &lt;mx:Script&gt;
          &lt;![CDATA[
              import mx.binding.utils.BindingUtils;
              import components.preview.PreviewPlayEvent;
              import mx.controls.Button;
              import components.preview.PreviewPlay;
              import components.content.contents.FixedHelp.FixedHelp;
              import mx.events.FlexEvent;
              import mx.core.Application;
              import mx.events.ToolTipEvent;
              import flash.utils.describeType;
              import mx.utils.ObjectUtil;
              import components.remix.PadDisplay.PadContent;
              import components.remix.PadDisplay.PalletteCode;
              import mx.core.IUIComponent;
              import mx.controls.Image;
              import mx.managers.DragManager;
              import mx.core.DragSource;
              import mx.events.DragEvent;
  
              // Embed icon image.
              [Embed(source='assets/proxy.png')]
              public var dragImg:Class;
              private var _scrollEnabled:Boolean=true;
              private var _currentpath:String="";
  
              public static const TYPE_ARRAY:Array=["loop", "one-shot sample", "stem", "track"]
  
  
              private function _creationcomplete(e:FlexEvent=null):void
              {
  
                  addEventListener(Event.ENTER_FRAME, enterframe, false, 0, true);
                  addEventListener(PreviewPlayEvent.PLAY, previewplayrequest, false, 0, true);
                  addEventListener(PreviewPlayEvent.STOP,previewstoprequest,false,0,true)
  
  
              }
  
              private function previewplayrequest(e:PreviewPlayEvent):void
              {
                  _currentpath=e._path;
                  //Application.application.previewplay(e._path)
                  invalidateList();
              }
              private function previewstoprequest(e:PreviewPlayEvent):void
              {
                  _currentpath="";
                  //Application.application.previewplay(e._path)
                  invalidateList();
              }
  
              public function get critera():String
              {
                  return _currentpath;
              }
  
              public function set criteria(value:String):void
              {
                  _currentpath=value;
              }
  
              private function enterframe(e:Event):void
              {
                  if (Application.application.hashelp == false)
                  {
  
                  }
                  else
                  {
                      removeEventListener(Event.ENTER_FRAME, enterframe);
                      var xml:XML=Application.application.helpxml;
                      var fh:FixedHelp=Application.application.fixedhelp;
                      var helptext:String=Application.application.helpxml.studio.loops.text;
                      fh.addItem(helptext, this);
                  }
              }
  
              private function mdhandler(e:MouseEvent):void
              {
                  describeType(e.currentTarget)
                  e.currentTarget.toString()
  
  
  
                  if (e.currentTarget.selectedItem != null &amp;&amp; getQualifiedClassName(e.target) != "mx.controls::Button")
                  {
                      _scrollEnabled=false
  
                      var dragdata:XML=XML(e.currentTarget.selectedItem) as XML
                      var ds:DragSource=new DragSource()
  
                      var dragdataasObject:Object=ObjectUtil.copy(e.currentTarget.selectedItem)
  
                      ds.addData(dragdataasObject, PadContent.LOOP_FORMAT);
                      //trace(ds.dataForFormat(PadContent.LOOP_FORMAT)) // I expect xml data to trace out here but it does not
                      var imageproxy:Image=new Image();
                      imageproxy.source=dragImg;
                      imageproxy.height=40;
                      imageproxy.width=40;
                      DragManager.doDrag(this, ds, e, imageproxy, (this.x - e.stageX) + 40, (this.y - e.stageY) + 130)
                      this.selectedItem=null;
                  }
                  else
                  {
                      e.stopImmediatePropagation();
                  }
  
              }
  
  
              private function userLabelFunction(item:Object, column:DataGridColumn):String
              {
                  var newstr:String=new String(item.t + "\n" + TYPE_ARRAY[item.ty])
                  return newstr;
              }
  
              private function catFunction(item:Object, column:DataGridColumn):String
              {
                  var newstr:String=TYPE_ARRAY[item.ty];
                  return newstr;
              }
  
  
              private function bpmFunction(item:Object, column:DataGridColumn):int
              {
  
                  var newstr:Number=new Number(item.bp);
                  return newstr;
              }
  
              private function beatCountFunction(item:Object, column:DataGridColumn):int
              {
                  var newstr:int=new int(item.bc);
                  return newstr;
              }
  
              private function sortbpm(obj1:Object, obj2:Object):int
              {
                  var valueA:Number=obj1.bp;
                  var valueB:Number=obj2.bp;
                  return ObjectUtil.numericCompare(valueA, valueB);
              }
  
              private function sortbeatcount(obj1:Object, obj2:Object):int
              {
                  var valueA:Number=obj1.bc;
                  var valueB:Number=obj2.bc;
                  return ObjectUtil.numericCompare(valueA, valueB);
  
              }
  
              public function get scrollEnabled():Boolean
              {
                  return _scrollEnabled;
              }
  
              public function set scrollEnabled(value:Boolean):void
              {
                  _scrollEnabled=value;
              }
  
              override protected function dragScroll():void
              {
                  if (_scrollEnabled)
                  {
                      super.dragScroll();
                  }
              }
          ]]&gt;
      &lt;/mx:Script&gt;
  
  
      &lt;mx:columns&gt;
          &lt;mx:DataGridColumn dataField="r"
                             headerText=""
                             itemRenderer="components.content.contents.datagrids.ImageRendererLoops"/&gt;
          &lt;mx:DataGridColumn dataField="t"
                             headerText="Title"
                             labelFunction="userLabelFunction"/&gt;
          &lt;mx:DataGridColumn dataField="bc"
                             headerText="Beats"
                             labelFunction="beatCountFunction"
                             sortCompareFunction="sortbeatcount"/&gt;
          &lt;mx:DataGridColumn dataField="BPM"
                             headerText="BPM"
                             labelFunction="bpmFunction"
                             sortCompareFunction="sortbpm"/&gt;
          &lt;mx:DataGridColumn itemRenderer="components.preview.PreviewPlay"/&gt;
  
      &lt;/mx:columns&gt;
  
  &lt;/mx:DataGrid&gt;
  </code></pre>
  
  <p><strong>Item Renderer</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml"
           implements="mx.controls.listClasses.IDropInListItemRenderer"&gt;
      &lt;mx:Script&gt;
          &lt;![CDATA[
              import mx.controls.DataGrid;
              import components.content.contents.datagrids.LoopMastersDataGrid;
              import components.remix.PadDisplay.PadContent;
              import mx.controls.listClasses.BaseListData;
  
              [Embed(source='assets/play_20.png')]
              [Bindable]
              public var play20Img:Class;
  
              public static const PLAYING:String="playing";
              public static const LOADING:String="loading";
              public static const IDLE:String="idle";
  
  
              private var _listData:BaseListData;
              private var _bpm:int;
              private var _path:String;
              private var _state:String="idle";
  
              public function get listData():BaseListData
              {
                  return _listData;
              }
  
              public function set listData(value:BaseListData):void
              {
                  _listData=value;
                  var criteria:String = (_listData.owner as LoopMastersDataGrid).critera;
  
                  if(this._path==criteria)
  
                  {
                      // this track is playing
                      previewbutton.styleName="stopPreviewButtonStyle";
  
                  }else
  
                  {
                     // this track is not playing
                     previewbutton.styleName="playPreviewButtonStyle";
  
                  }
  
                  //trace("list data crit=="+criteria);
  
              }
  
              override public function set data(value:Object):void
              {
                  super.data=value;
                  this._path=new String(PadContent.LOOP_ROOT + value.r + "/" + value.u + ".rocudo");
                  this._bpm=value.bp;
                  //trace(this._path);
  
  
              }
  
              private function sendPreviewRequest(event:Event):void
              {
                  switch(this._state)
  
                  {
                      case(PreviewPlay.IDLE):
                      (listData.owner as LoopMastersDataGrid).dispatchEvent(new PreviewPlayEvent(PreviewPlayEvent.PLAY,this._bpm,this._path));
                      break;
  
                      case(PreviewPlay.LOADING):
                      //  preview play probably shouldnt care about loading
                      break;
  
                      case(PreviewPlay.PLAYING):
                      (listData.owner as LoopMastersDataGrid).dispatchEvent(new PreviewPlayEvent(PreviewPlayEvent.STOP,this._bpm,this._path));
                      break;
  
  
                  }
  
               //dispatchEvent(new PreviewPlayEvent(PreviewPlayEvent.PLAY,this._bpm,this._path));
              }
  
          /** override protected function commitProperties():void
          {
              super.commitProperties();
              this._state=PreviewPlay.IDLE;
          }**/
          ]]&gt;
      &lt;/mx:Script&gt;
  
      &lt;mx:Button id="previewbutton"
                 width="20"
                 height="20" click="sendPreviewRequest(event)" styleName="playPreviewButtonStyle"&gt;
  
      &lt;/mx:Button&gt;
  
  &lt;/mx:HBox&gt;
  </code></pre>
  
  <p><strong>Update</strong></p>
  
  <p>I removed my mouse down handler from the datagrid and removed the cusom component. Clicking on a item in the datagrid makes the datagrid scroll so that the item selected appears first in the list. This is the behaviour I need to stop.</p>