as3 get zip file on phone from app - file path then unzip

纵然是瞬间 提交于 2019-12-04 18:27:47

You have to write your own file browser using flash.filesystem.File class.

Below are few methods from my own FileBrowser class:

/**
 * Displays root directories
 */
public function showRootFolders():void
{
    if (!m_oLocation) m_oLocation = new File();
    var rootDirs:Array = File.getRootDirectories();
    if (!m_vRootDirs) m_vRootDirs = new Vector.<File>();

    for (var i:int = 0; i < rootDirs.length; i++)
    {
        var item:File = rootDirs[i];
        if (i < m_vRootDirs.length) m_vRootDirs[i] = item;
        else m_vRootDirs.push(item);
    }

    if (contains(m_oLevelUp)) removeChild(m_oLevelUp);
    m_oFolderName.setLabel("ROOT");
    m_oFolderInfo.setLabel(rootDirs.length + " Folder(s), " + 0 + " File(s)");

    displayList(m_vRootDirs);
}


/**
 * <p>Gets all files from requested location (File) and updates list view.</p>
 * @param    p_oLocation
 * @param    p_bLinkToParent
 */
public function listLocation(p_oLocation:File, p_bLinkToParent:Boolean=false):void
{
    trace("listLocation(p_oLocation:File):void");
    //folder or file
    if (p_oLocation.isDirectory)
    {
                    clear()://clear list view
        var _vItems:Vector.<File> = new Vector.<File>();

        var files:Array = p_oLocation.getDirectoryListing();

        trace("files.length:"+files.length);
        var _nFiles:int = 0;
        var _nFolders:int = 0;

        for (var i:int = 0; i < files.length; i++)
        {
            var item:File = files[i];

            if (item.isDirectory) _nFolders++;
            else _nFiles++;

            _vItems.push(item);
        }

        if (p_bLinkToParent)
        {
            if (p_oLocation.parent != null || m_vRootDirs.length > 0)
            {
                //return button
                m_oParent = p_oLocation.parent;

                addChild(m_oLevelUp);
            }
            else
            {
                if (contains(m_oLevelUp)) removeChild(m_oLevelUp);
            }
        }
        else
        {
            m_vRootDirs.length = 0;
            if (contains(m_oLevelUp)) removeChild(m_oLevelUp);
            m_oParent = null;
        }

        m_oFolderInfo.setLabel(_nFolders + " Folder(s), " + _nFiles + " File(s)");

        m_oFolderName.setLabel(p_oLocation.name);

        displayList(_vItems);
    }
}


/**
 * <p>Display given file list in the list view</p>
 * @param    p_vFileList
 */
protected function displayList(p_vFileList:Vector.<File>):void
{
    trace("displayList(p_vFileList:Vector.<File>):void");
    clear();//clear list view
    //sort
    p_vFileList = p_vFileList.sort(sortByName)
    //[...]
    //build
    var data:Vector.<ListItemData> = new Vector.<ListItemData>();

    var p:Point = new Point();
    for (var i:int = 0; i < p_vFileList.length; i++)
    {
        var item:File = p_vFileList[i];
                    //here do what ever you like with the list of files
                    //e.g. populate the list view with different type based on the file extension, type etc.
        }
}

I hope it will help you a bit,

best regards

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!