2016-01-25 45 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。 –