mx:TileList:如果激活allowMultipleSelection,为什么drag不起作用

时间:2012-05-14 08:39:07

标签: actionscript-3 air flash-builder

我使用TileList来显示图像,就像一个图库。 一开始,我只激活拖动选项。

<mx:TileList xmlns:fx="http://ns.adobe.com/mxml/2009"
         xmlns:s="library://ns.adobe.com/flex/spark"
         xmlns:mx="library://ns.adobe.com/flex/mx"
         columnWidth="120"
         rowHeight="150"
         paddingLeft="2"
         paddingRight="2"
         paddingTop="2"
         paddingBottom="2"
         itemRenderer="fr.ui.display._43Imagerie.TileUnit2"
         doubleClickEnabled="true"
         dragEnabled="true"
         dropEnabled="true"
         dragMoveEnabled="true"
         verticalScrollPolicy="on"
         >

现在我尝试添加多种选择的可能性。

ItemRenderer是:

<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" 
       verticalScrollPolicy="off" 
       horizontalScrollPolicy="off"
       width="120"
       height="150"
       borderVisible="false"
       xmlns:s="library://ns.adobe.com/flex/spark"
       creationComplete="onEvent()"

       >
<mx:Script>
    <![CDATA[
        import fr.util.imageTransform;

        import mx.controls.Image;
        import mx.core.UIComponent;
        import mx.events.DragEvent;
        import mx.managers.DragManager;

        import org.osmf.utils.URL;

        import spark.effects.Rotate;

        [Bindable]
        [Embed(source="icon/imagerie/rotate.png")]
        private var rotationArrowClass:Class;

        private var _file:File;
        private var _selected:Boolean;
        private var _sauvBMD:BitmapData;
        public var wasScaled:Boolean = false;
        public var deleted:Boolean = false;
        private var bgCenterX:Number;
        private var bgCenterY:Number;
        private var _dragDownPt:Point;

        [Bindable]
        public var angle:int = 0;

        private var dragBitmapData : BitmapData;

        private function onEvent():void
        {
            // iconCanvas.addEventListener(MouseEvent.DOUBLE_CLICK, onDoubleClick);
            // double click gere ds wPlanchePhoto3

        }








        private function rotationImage(e:MouseEvent):void
        {

            var rot:Rotate = new Rotate();
            rot.angleBy = 90;
            rot.duration = 1000;
            rot.autoCenterTransform = true;
            rot.target = iconCanvas;
            rot.play();

        }

        private function radiansToDegrees(radians:Number):Number {
            var degrees:Number = radians * (180 / Math.PI);
            return degrees;
        }

        private function degreesToRadians(degrees:Number):Number {
            var radians:Number = degrees * (Math.PI / 180);
            return radians;
        }

        public function set image(im:BitmapData):void
        {
            this._sauvBMD=im;
        }

        public function get image() :BitmapData
        {
            return this._sauvBMD;
        }



        protected function iconCanvas_mouseDownHandler(event:MouseEvent):void
        {

            // on enregistre la point de départ 
            _dragDownPt = new Point(mouseX,mouseY); 
            // puis on écoute l'éventuel déplacement de la souris 
            this.addEventListener(MouseEvent.MOUSE_MOVE,_onMouseMoveDuringDrag);


        }

        private function _onMouseMoveDuringDrag(evt:MouseEvent):void {
            // astuce pour s'assurer que la souris a vraiment bougee volontairement 
            if(Math.abs(_dragDownPt.x - mouseX) <= 2 && Math.abs(_dragDownPt.y - mouseY) <= 2)
                return; 

            else{
                dragBitmapData = new BitmapData(iconCanvas.width, iconCanvas.height,true, 1);
                dragBitmapData.draw(iconCanvas);

                var transfert:Clipboard = new Clipboard();
                transfert.setData(ClipboardFormats.BITMAP_FORMAT,Bitmap(iconCanvas.content).bitmapData);

                // only allow the file to be copied
                var dragOptions:NativeDragOptions = new NativeDragOptions();
                dragOptions.allowMove=false;
                dragOptions.allowCopy = true;
                dragOptions.allowLink = false;

                // begin the drag
                NativeDragManager.doDrag(this, transfert, dragBitmapData, null, dragOptions);
            }
            // dispatch de l'event depuis le parent pour pouvoir écouter cet event dans l'application 
        }



    ]]>
</mx:Script>

<s:BorderContainer
                   id="bcImage"
                   width="120"
                   height="99%"
                   borderVisible="true"
                   borderColor="#FFFFFF"
                   borderWeight="1"
                   cornerRadius="6"
                   backgroundAlpha=".4"
                   backgroundColor="#5f5f5f"
                   >




    <mx:Canvas id="cvsImage" width="100%">
        <mx:SWFLoader id="rotationArrow" source="{rotationArrowClass}" height="18" width="18" x="3" y="3" visible="true" click="rotationImage(event);" alpha=".5"/>
        <s:Label x="23" y="3" width="82" fontSize="11" fontWeight="normal" text="{data.imDate}"
                 textAlign="right" color="#000000"/>    


        <mx:Image id="iconCanvas" x="10" y="20" width="99" height="99" horizontalAlign="center"
                  maintainAspectRatio="true" scaleContent="true"
                  source="{data.imURL}" 
                  verticalAlign="middle" mouseDown="iconCanvas_mouseDownHandler(event)"
                  >

        </mx:Image>
    </mx:Canvas>

    <s:VGroup width="100%" y="124" height="25" bottom="1" left="3" right="3" paddingBottom="0" paddingTop="4" gap="0">
        <s:Label text="{data.imType}" height="50%" fontSize="10" paddingBottom="1"
                 fontWeight="normal" width="99%" textAlign="center" color="#000000"/>
        <s:Label text="{data.imStade}" fontSize="10" textAlign="center" paddingTop="1"
                 fontWeight="normal" width="99%" color="#000000"/>  

    </s:VGroup>

</s:BorderContainer>

如果此选项为true(allowMultipleSelection),拖动停止工作,你知道为什么吗?

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

添加allowMultipleSelection =“true”对我来说很好。我正在使用最新版本的Flash Player在Mac上运行。它起初看起来有点片状,但刷新页面之后效果很好。我项目中没有的只有你的数据提供者和项目渲染器。我真的怀疑你的项目渲染器会引起问题,除非你在那里做一些疯狂的事情。检查您是否拥有最新的Flash Player。