(Adobe) AIR,如何將桌面的檔案,拖拉到AIR程式裡面

要把電腦裡面(桌面或是磁碟裡面的檔案)

拖拉(拖曳,Drag And Drop)到 AIR程式裡面

 

Q: 要把電腦裡面(桌面或是磁碟裡面的檔案)

     拖拉(拖曳,Drag And Drop)到 AIR程式裡面

 

 

這個東西,目前FLEX作不到,只能用 AIR來作。

我們打開 FLEX,新增一個專案時,務必選用 AIR(而非flash)

 

我找到不錯的範例,請參考

http://coenraets.org/blog/2007/06/air-to-desktop-drag-and-drop-two-simple-utility-classes/

---------------------------------------------------------------------------------------------

另外一個範例更簡單。

但我突然忘記出處了,實在很對不起原作者

I Forget  where dose this Sample Code Come from?   Sorry Very Much.

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" creationComplete="init()">
 <mx:Script>
 <![CDATA[
                        import mx.controls.Alert;
                        import mx.controls.Image;
                        import flash.filesystem.File;
                        import flash.desktop.Clipboard;
                     import flash.desktop.ClipboardFormats;
                        import flash.events.NativeDragEvent;
                        import flash.desktop.NativeDragManager;

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

                public function onDragEnter(event:NativeDragEvent):void{
                   NativeDragManager.acceptDragDrop(this);
                }

                public function onDrop(event:NativeDragEvent):void{
                    var dropfiles:Array = event.clipboard.getData(ClipboardFormats.FILE_LIST_FORMAT) as Array;
                                for each (var file:File in dropfiles){
                                    switch (file.extension){
                                case "png" :
                                        addImage(file.nativePath);
                                        break;
                                case "jpg" :
                                        addImage(file.nativePath);
                                        break;
                                case "gif" :
                                        addImage(file.nativePath);
                                        break;
                                default:
                                   Alert.show("Unmapped Extension");
                            }
                      }
                }

                public function onDragExit(event:NativeDragEvent):void{
                    trace("Drag exit event.");
                }

                private function addImage(nativePath:String):void{
                        var img:Image = new Image();
                        if(Capabilities.os.search("Mac") >= 0){
                         img.source = "file://" + nativePath;
                        } else {
                         img.source = nativePath;
                        }
                        this.addChild(img);
                }

 

  ]]>
  </mx:Script>
  <mx:Label text="Drag an Image from File System here..." />
  </mx:WindowedApplication>

 

 

我將思想傳授他人, 他人之所得,亦無損於我之所有;

猶如一人以我的燭火點燭,光亮與他同在,我卻不因此身處黑暗。----Thomas Jefferson

線上課程,遠距教學 (Web Form 49hr)  https://dotblogs.com.tw/mis2000lab/2016/02/01/aspnet_online_learning_distance_education_VS2015

線上課程,遠距教學 (ASP.NET MVC 75hr)  https://dotblogs.com.tw/mis2000lab/2018/08/14/ASPnet_MVC_Online_Learning_MIS2000Lab

ASP.NET MVC線上課程 第一天 免費看 (5.5小時) 

寫信給我,不要私訊 --  mis2000lab (at) yahoo.com.台灣  或  school (at) mis2000lab.net


ASP.NET遠距教學、線上課程(Web Form + MVC)。 第一天課程, "完整" 試聽。 

................   facebook社團   https://www.facebook.com/mis2000lab   ......................

................  YouTube (ASP.NET) 線上教學影片  https://www.youtube.com/channel/UC6IPPf6tvsNG8zX3u1LddvA/

 

Blog文章 "附的範例" 無法下載,請看 這裡 ...... https://dotblogs.com.tw/mis2000lab/2016/03/14/2008_2015_mis2000lab_sample_download

請看我們的「售後服務」範圍(嚴格認定)

......................................................................................................................................................

...................................................................................................................................................... 

[遠距教學、教學影片] ASP.NET (Web Form) 課程 上線了!MIS2000Lab.主講

事先錄製好的影片,並非上課時側錄!   觀看影片時,有如我「一對一」跟您面對面講課

 

ASP.NET MVC 5 線上教學

累積時數約 75小時...... 第一天(5.5小時)完整內容,"免費"讓您評估