开发者

Stop List From Scrolling

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?

Extended datagrid

<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)">

    <mx:Script>
        <![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 && 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();
                }
            }
        ]]>
    </mx:Script>


    <mx:columns>
        <mx:DataGridColumn dataField="r"
                           headerText=""
                           itemRenderer="components.content.contents.datagrids.ImageRendererLoops"/>
        <mx:DataGridColumn dataField="t"
                           headerText="Title"
                           labelFunction="userLabelFunction"/>
        <mx:DataGridColumn dataField="bc"
                           headerText="Beats"
                           labelFunction="beatCountFunction"
                           sortCompareFunction="sortbeatcount"/>
        <mx:DataGridColumn dataField="BPM"
                           headerText="BPM"
                           labelFunction="bpmFunction"
                           sortCompareFunction="sortbpm"/>
        <mx:DataGridColumn itemRenderer="components.preview.PreviewPlay"/>

    </mx:columns>

</mx:DataGrid>

Item Renderer

<?xml version="1.0" encoding="utf-8"?>
<mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml"
         implements="mx.controls.listClasses.IDropInListItemRenderer">
    <mx:Script>
        <![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;
        }**/
        ]]>
    </mx:Script>

    <mx:Button id="previewbutton"
               width="20"
               height="20" click="sendPreviewRequest(event)" styleName="playPreviewButtonStyle">

    </mx:Button>

</mx:HBox>

Update

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜