Air中文件拖放

1、文档内部元件的拖放:

           private function init():void
            {
                this.readConfigFile();
                this.addEventListener(DragEvent.DRAG_ENTER, enterHandler);
                this.addEventListener(DragEvent.DRAG_DROP, dropHandler);
            }

             private function enterHandler(event:DragEvent):void
            {
                var dragSource:DragSource = event.dragSource;
                if(dragSource.hasFormat('createComponent'))
                {
                    DragManager.acceptDragDrop(this);
                }
            }
            
            private function dropHandler(event:DragEvent):void
            {
                var dragSource:DragSource = event.dragSource;
                var compName:String = dragSource.dataForFormat('createComponent') as String;
            }



2、从桌面拖拽文件到air应用程序,(这个其实和通过打开浏览窗口导入文件类似)

            private function init():void
            {
                this.addEventListener(NativeDragEvent.NATIVE_DRAG_ENTER, onDragIn);
                this.addEventListener(NativeDragEvent.NATIVE_DRAG_DROP,onDrop);
            }

            private function onDragIn(event:NativeDragEvent):void
            {
                if(event.clipboard.hasFormat(ClipboardFormats.FILE_LIST_FORMAT))
                {
                    var files:Array = event.clipboard.getData(ClipboardFormats.FILE_LIST_FORMAT) as Array;
                    DragManager.acceptDragDrop(this);
                }
                else
                {
                    trace('-----')
                }
            }
            
            private function onDrop(event:NativeDragEvent):void
            {
                var files:Array = event.clipboard.getData(ClipboardFormats.FILE_LIST_FORMAT) as Array;
                var num:int = files.length;
                var fStream:FileStream;
                var sourceFile:File;
                for(var i:int = 0; i < num; i++)
                {
                    sourceFile = files[i] as File;
                    if(sourceFile.extension == 'png' || sourceFile.extension == 'jpg')
                    {
                        
                        var destination:File = File.documentsDirectory;
                        destination = destination.resolvePath("AIR Test/test2.bmp");
                        try
                        {
                            sourceFile.copyTo(destination, true);
                        }
                        catch (error:Error)
                        {
                            trace("Error:", error.message);
                        }
                    }
                }
            }


3、从air程序中拖拽文件到桌面上

     待续。。。



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值