zoukankan      html  css  js  c++  java
  • FLASH BUILDER AIR 打开本地文件及保存列表

    首先需要一个容器

    <s:BorderContainer id="container" width="100%" height="100%" backgroundAlpha="0" borderAlpha="0">                
    </s:BorderContainer>

    AS代码:

    先添加侦听

    container.addEventListener(NativeDragEvent.NATIVE_DRAG_ENTER, nativeDragEnterHandler);
    container.addEventListener(NativeDragEvent.NATIVE_DRAG_DROP, nativeDragDropHandler);
     1 private function nativeDragEnterHandler(e:NativeDragEvent):void
     2             {
     3                 NativeDragManager.dropAction = NativeDragActions.COPY;
     4                 NativeDragManager.acceptDragDrop(container);
     5             }
     6             
     7             private function nativeDragDropHandler(e:NativeDragEvent):void
     8             {
     9                 var clip:Clipboard = e.clipboard;
    10                 if(clip.hasFormat(ClipboardFormats.FILE_LIST_FORMAT))
    11                 {
    12                     var fileList:Array = clip.getData(ClipboardFormats.FILE_LIST_FORMAT) as Array;
    13                     var fileLen:uint = fileList.length;
    14                     
    15                     var item:Object;
    16                     var urlStr:String;
    17                     var hasLen:int = list_DG.length;
    18                     for (var i:uint = 0; i < fileLen; i ++) 
    19                     {
    20                         var file:File = fileList[i] as File;
    21                         urlStr = new String(file.nativePath);
    22                         if (urlStr.slice( -5) == ".ttpl") {
    23                             trace("212")//loadXML(urlStr);
    24                         }else{
    25                             item = new Object();
    26                             item.num = hasLen+i+1;
    27                             item.name = urlStr.slice(urlStr.lastIndexOf("\")+1,-4);
    28                             item.name = item.name.slice(item.name.lastIndexOf("/")+1);
    29                             item.url = file.url.slice(-4)==".mp3"?"mp3.png":file.url;
    30                             item.snd = file.url.slice(-4)==".mp3"?file.url:"";
    31                             item.type = file.url.slice(-4)==".mp3"?0:1;//0mp3 1pic
    32                             
    33                             list_DG.addItem(item);//list_DG是Arraycollection
    34                         }
    35                     }
    36                     saveList();//保存列表xml类型
    37                 }
    38             }

    savelList:

     1 private function saveList():void{
     2                 var list:XML = <ImgList></ImgList>;    
     3                 
     4                 for(var i:int = 0; i<list_DG.length;i++){
     5                     var item:XML = <item time="0:00" />;
     6                     item.@name = list_DG.getItemAt(i).name;
     7                     item.@url = list_DG.getItemAt(i).url;
     8                     item.@snd = list_DG.getItemAt(i).snd;
     9                     item.@type = list_DG.getItemAt(i).type;
    10                     list.appendChild(item);
    11                 }
    12                 var file:File = new File(File.applicationDirectory.nativePath+"/data/last.xml");
    13                 var fs:FileStream = new FileStream();
    14                 fs.open(file, "write");
    15                 fs.writeUTFBytes(list.toXMLString());
    16                 fs.close();    
    17             }
  • 相关阅读:
    介绍我的一位同事的开源RSS阅读器
    开源协议概谈[转载]
    编译错误CS1595
    JAVA和C#,武当和少林之争!
    IBatisNet之获取和操作SQL语句
    Linux能否靠架构取得胜利
    开源CMS Alfresco 1.0 发布
    在asp.net页面上得到Castle容器的实例
    IBatisNet 之 自动生成主关键字
    onvaluechange事件
  • 原文地址:https://www.cnblogs.com/LLLoveLL/p/3332829.html
Copyright © 2011-2022 走看看