<mx:DataGrid id="datagrid" y="10" width="501" horizontalCenter="-9" dragEnabled="true">
________________________________ From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of bsensale Sent: Thursday, August 07, 2008 12:43 PM To: flexcoders@yahoogroups.com Subject: [flexcoders] Re: Problems with nudgescrolling when programatically clicking items in DataGrid Thanks for the quick reply. Is there a sample anywhere of how to do this? Or could someone put the sample code into the little app below? Thanks! --- In flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> , "Alex Harui" <[EMAIL PROTECTED]> wrote: > > set dragEnabled=true > > or use the mx_internal mouseX/Y override in UIComponent > > ________________________________ > > From: flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> [mailto:flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> ] On > Behalf Of bsensale > Sent: Thursday, August 07, 2008 6:54 AM > To: flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> > Subject: [flexcoders] Problems with nudgescrolling when programatically > clicking items in DataGrid > > > > Hello, > > I'm writing some tools to automate clicking items in datagrids through > mouse events. Right now that means scrolling to an index, and calling > mouseDown, then mouseUp on datagrid.indexToItemRenderer(idx). The > problem is if the physical mouse cursor happens to be below the > datagrid when the mouseDown is called, the datagrid will nudge scroll > before the mouseUp is called if there's any delay whatsoever. > > I don't want to necessarily disable nudge scrolling for the grid; this > is merely for automation purposes, so I was wondering if there was any > way on the fly to either force the mouse to move into the datagrid so > it won't nudge scroll, or to somehow disable nudge scrolling on the fly > quickly, so I can run the automation. > > I've put together a simple (and poorly written, sorry!) app showing the > behavior. If you click the button, it dispatches a mouseDown event to > item 0 in the datagrid, then sets up a 10 ms timer. When that timer > fires, it checks if the item is still visible before firing the mouseUp. > > <?xml version="1.0" encoding="utf-8"?> > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml <http://www.adobe.com/2006/mxml> > <http://www.adobe.com/2006/mxml <http://www.adobe.com/2006/mxml> > " > layout="absolute"> > <mx:Script> > <![CDATA[ > import mx.controls.Text; > import flash.sampler.NewObjectSample; > import flash.utils.setInterval; > function onButtonClick(event:MouseEvent):void { > textArea.text = ""; > var mouseDown:MouseEvent = new MouseEvent > (MouseEvent.MOUSE_DOWN, true, false, 0, 0, null, false, false, false, > true); > datagrid.scrollToIndex(0); > var obj:Object = datagrid.indexToItemRenderer(0); > if(obj == null) { > textArea.text += "Object was null!\n"; > } > else { > textArea.text += "Object: " + obj.toString() + "\n"; > obj.dispatchEvent(mouseDown); > } > > > var t:Timer = new Timer(10, 1); > t.addEventListener(TimerEvent.TIMER, timerHandler); > t.start(); > } > > function timerHandler(evt:Object) { > var mouseUp:MouseEvent = new MouseEvent > (MouseEvent.MOUSE_UP, true, false, 0, 0, null, false, false, false, > false); > var obj2:Object = datagrid.indexToItemRenderer(0); > if(obj2 == null) { > textArea.text += "Object2 was null!\n"; > } > else { > textArea.text += "Object2: " + obj2.toString() > + "\n"; > obj2.dispatchEvent(mouseUp); > } > } > ]]> > </mx:Script> > <mx:DataGrid id="datagrid" y="10" width="501" horizontalCenter="-9"> > <mx:dataProvider> > <mx:Object col1="a" col2="a"/> > <mx:Object col1="b" col2="b"/> > <mx:Object col1="c" col2="b"/> > <mx:Object col1="d" col2="b"/> > <mx:Object col1="e" col2="b"/> > <mx:Object col1="f" col2="b"/> > <mx:Object col1="g" col2="b"/> > <mx:Object col1="h" col2="h"/> > <mx:Object col1="i" col2="i"/> > <mx:Object col1="j" col2="j"/> > </mx:dataProvider> > <mx:columns> > <mx:DataGridColumn headerText="Column 1" dataField="col1"/> > <mx:DataGridColumn headerText="Column 2" dataField="col2"/> > </mx:columns> > </mx:DataGrid> > <mx:Button id="button" y="479" label="Click Me!" > click="onButtonClick(event)" horizontalCenter="0"/> > <mx:TextArea id="textArea" y="216" width="501" height="255" > horizontalCenter="-9"/> > > </mx:Application> >