2016-01-25 43 views
1

我有一個<s:List />,其中包含一堆files。在右鍵點擊時,我在鼠標的(x,y)位置打開一個菜單,讓用戶「打開文件位置」。我的努力是打開文件位置並選擇(不打開)文件,就像Window的資源管理器一樣。最近我打開父文件夾並使用file.openWithDefaultApplication();,它打開文件所在的文件夾而不顯示用戶實際文件。使用as3打開文件位置

MXML

 <s:List 
      id="fileDownList" 
      height="100%" 
      width="100%" 
      dataProvider="{files}" 
      labelField="name" 
      allowMultipleSelection="false" 
      rightClick="rightMouseDown(event)" 
      itemRollOver="currentItem = event.itemRenderer.data" 
      /> 

AS3

private function rightMouseDown(event:MouseEvent):void { 
     createMenu(currentItem, event.stageX, event.stageY); 
    } 

     private function createMenu(item:Object, xPos:int, yPos:int):void { 
     if (menu != null) { 
      menu.hide(); 
     } 
     var menuItems:Array = []; 

     menuItems.push({label:"Open File Location"), 
      func: function run():void{ 
       //runs on doMenuAction listener, need to open location here 

      } 

     }); 

     if (menuItems.length > 0) { 
      menu = Menu.createMenu(tree, menuItems); 
      //noinspection JSValidateTypes 
      menu.addEventListener(MenuEvent.ITEM_CLICK, doMenuAction); 
     } 

     if (menu != null) { 
      menu.show(xPos, yPos); 
     } 

    } 

enter image description here enter image description here

+0

不清楚你在問什麼。另外 - 基於瀏覽器?空氣? –

+0

@Sleeper什麼部分不清楚,所以我可以澄清?這是一個AIR桌面應用程序。 –

+1

@Sleeper,你有沒有使用Windows文件搜索?當它給你一個文件名的列表,你可以右鍵單擊一個,然後選擇「打開文件位置」,它會打開一個新的資源管理器窗口,並自動向下滾動到所選文件的位置,並自動突出顯示/選擇... –

回答

1

我最終什麼事做是創建一個.cmd文件(只是一個重命名的.bat文件),該文件打開一個目錄,其文件名爲/select

AS3

private function run():void{ 
         var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo(); 
         var file:File = File.applicationDirectory.resolvePath("C:\\Users\\Me\\Desktop\\launcher.cmd"); 
         nativeProcessStartupInfo.executable = file; 

         var processArgs:Vector.<String> = new Vector.<String>(); 
         processArgs[0] = item.url; 
         nativeProcessStartupInfo.arguments = processArgs; 

         process = new NativeProcess(); 
         process.start(nativeProcessStartupInfo); 

        } 

launcher.cmd

@ECHO OFF 
SET /a LOCATION=%1 
explorer /select, %1 
2

試試看......結果爲有可能使用NativeProcess和Explorer.exe參數

繼承人一個基本的AS3唯一的例子。請測試,然後應用邏輯代碼:

//# String holds required file path 
//# example ::: myfileURL = "C:\\myFolder\\mySubFolder\\myImage.jpg"; 
public var myfileURL : String = ""; 

myfileURL = "C:\\VC1\\Tests\\CoolSong.mp3"; //update this before running function 
openWindows_FileSelected(); //run the function 

private function openWindows_FileSelected():void 
{ 
    var explorer:File = new File("C:\\Windows\\explorer.exe"); 

    if (explorer.exists) 
    { 
     var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo(); 
     nativeProcessStartupInfo.executable = explorer; 

     var args:Vector.<String> = new Vector.<String>(); 

     args.push("/select,"); 
     args.push(myfileURL); //file to auto-highlight 

     nativeProcessStartupInfo.arguments = args; 
     process = new NativeProcess(); 
     process.start(nativeProcessStartupInfo); 
    } 

} 


PS:

我能想到的......由於您使用File你必須獲得唯一的陷阱通過文件的.nativePath命令其路徑的一個字符串,它賦予像一個字符串:
"C:/myFolder/mySubFolder/myImage.jpg"

但上面的代碼工作必須做一次更換(試行字符串方法Split/Join),並把它LO像:
"C:\\myFolder\\mySubFolder\\myImage.jpg"
如果你不更換兩個反斜槓,則喜歡Explorer.exe不會所有的單斜槓,你會總是得到一個錯誤...

+1

文件具有可用於代替拆分和連接的「url」屬性。 –

+0

啊!應該想到這一點。對於基於AIR的代碼仍然是新的。你的問題是我的第三次嘗試。只需要將AS3代碼重新編譯到Android。 –