Mastering the JSFL: 利用JSFL进行批处理操作(批量发布,交换元件,修改AS代码等等)

利用JSFL进行批处理操作:(批量发布,交换元件,修改AS代码等等)

 batch processing the fla files from the file lists

 

 下面我们利用jsfl来实现读取一个fla的文件列表,对其中的fla文件进行批处理操作

1.建立文件列表

   建立需要进行批处理的fla文件的文件列表list.txt,格式为一行一个绝对路径(由于多语言的问题,建立列表后,若文件路径中包含中文,必须将此文件列表以UTF8或者UNICODE编码保存)

   例如以下的格式:

 d:/Flash/Test/101.fla
 d:/Flash/Test/102.fla
 d:/Flash/Test/103.fla
 d:/Flash/Test/104.fla
 d:/Flash/Test/105.fla
 d:/Flash/Test/106.fla
 d:/Flash/Test/107.fla
 d:/Flash/Test/108.fla

 

2.建立,运行脚本.

   复制以下代码到一个jsfl文件(例如test.jsfl)中,存储在 Configuration 文件夹内,使其可用于 Flash 创作环境。默认情况下,Configuration 文件夹位于以下位置: 

   •    Windows® Vista™:
      引导驱动器/Users/ 用户名/Local Settings/Application Data/Adobe/Flash CS4/ 语言/Configuration/
   •    Windows XP:
      引导驱动器/Documents and Settings/ 用户名/Local Settings/Application Data/Adobe/Flash CS4/ 语言/Configuration/。

   Flash8 Flash CS3的位置类似。

此时在flash的命令菜单中增加了一个test的菜单.

  另一种运行方法是:倘若仍然找不到Configuration 文件夹,则把test.jsfl存储到d:/目录,

     从 Windows 命令行运行脚本:
      •    使用以下语法(根据需要添加路径信息):
          "flash.exe" d:/test.jsfl

 

3.单击这个test菜单,就可以对list.txt中的多个文件进行批处理操作了(比如:批量发布,交换元件,修改AS代码)。下面的是批量发布操作.

 // JavaScript Document

//  2009-11-22 20:18

//  BY  xcntime 

//  http://blog.csdn.net/xcntime
fl.outputPanel.clear();
var curTime;
var folderURI;
var fileURI;
var logFileURI ="
file:///c:/log.txt";
var fileTxt;
var indexFile=0;
var fileArray = new Array();
var procFiles = new Array();

try
{
    fileURI = selectFile("Select the file that contains the fla files list.");
    curTime = getCurrTime();
    fileIO("w+", logFileURI, "===="+curTime+"====/n");
    if(fileURI != null)
    {
        fileTxt = fileIO("r", fileURI);
        if(fileTxt != false )
        {
            fileArray = getFileArray(fileTxt);
            var curMem=Math.round(fl.getAppMemoryInfo(2) / 1024 / 1024);
            var indexCurFile =0;
            for(var i=0; i<fileArray.length; i++)
            {
                if(curMem <150)
                {
                    procFiles.push(fileArray[indexFile]);
                    fl.openDocument(procFiles[procFiles.length-1]);
                    indexFile++;
                }
                else
                {
                    //    alert(fl.documents);
                    procDocs(fl.documents);
                    i--;
                }
                curMem=Math.round(fl.getAppMemoryInfo(2) / 1024 / 1024);
                //   alert(curMem+"/n"+procFiles.length);
            }
            alert("last job.");
            procDocs(fl.documents);
        }
        else
        {
            alert("fail to read the file's content!")
        }
    }
    else
    {
        alert("You didnt select a file!");
    }
}
catch (e)
{
    alert("error:" + "/nname: " + e.name + "/nmsg: " + e.message);
}



//          get the date and time

function getCurrTime()
{
    var DateObj = new Date();
    var nowYear = DateObj.getFullYear();
    var nowMonth = DateObj.getMonth() + 1;
    var nowDate = DateObj.getDate();
    var nowDay = DateObj.getDay();
    var nowHour = DateObj.getHours();
    var nowMin = DateObj.getMinutes();
    var nowSec = DateObj.getSeconds();
    var curTime;
    nowMonth = nowMonth > 9 ? nowMonth : "0" + nowMonth;
    nowDate = nowDate > 9 ? nowDate : "0" + nowDate;
    nowHour = nowHour > 9 ? nowHour : "0" + nowHour;
    nowMin = nowMin > 9 ? nowMin : "0" + nowMin;
    nowSec = nowSec > 9 ? nowSec : "0" + nowSec;
    curTime = nowYear + "/" + nowMonth + "/" + nowDate + " " + nowHour + ":" + nowMin + ":" + nowSec;
    // alert(curTime);
    return curTime;
}


//  process the fla file

function procDoc(_myDoc)
{
    if(_myDoc.canTestMovie())
    {
        //   _myDoc.testMovie();
        fl.setActiveWindow(_myDoc);
        _myDoc.publish();
        fl.trace(_myDoc.path);
    }
    else
    {
        fl.trace(_myDoc.path+"/t/t"+"*(fail to process......)");
    }
    fl.outputPanel.save(logFileURI, true);
}


//  process the fla files

function procDocs(_myDocs)
{
    for(var i=0; i<_myDocs.length; i++)
    {
        procDoc(_myDocs[i]);
    }

    for(i=0; i<_myDocs.length; i++)
    {
        _myDocs[i].close();
    }
}


//          select a file surely

function selectFile(_txtPrompt)
{
    var _fileURI ;
    var _fileTxt;
    var _fileProc;
    var _posBack;

    _fileURI = fl.browseForFileURL("open", _txtPrompt);

    if(_fileURI == null )
    {
        alert("Warning!!!/nYou didnt select a file!");
    }
    else
    {
        if( - 1 == (_posBack = _fileURI.lastIndexOf("/")))
        {
            alert("the file's location is invailed!");
            _fileURI = null;
        }
        else
        {
            //  alert(_fileTxt);
        }
    }
    return decodeURI(_fileURI);
}



//    get the file list and make into array

function getFileArray(_fileTxt)
{
    var _fileArray = new Array();

    var CRLF =13;
    _fileArray = _fileTxt.split("/n");
    for(var i in _fileArray)
    {
        // the end char is "/n", so substr the string to del it
        if(_fileArray[i].charCodeAt(_fileArray[i].length-1)== CRLF)
        {
            _fileArray[i]=_fileArray[i].substr(0, _fileArray[i].length-1);
        }
        _fileArray[i] = pathToURI(_fileArray[i]);
    }
    return _fileArray;
}



//    convert the path to the URI

function pathToURI(_myPath)
{
    decodeURI(_myPath);
    _myPath = _myPath.replace(//g, "//");
    _myPath = _myPath.replace(g, "/");
    _myPath = _myPath.replace(/^([a-zA-Z]):/g, "
file:///$1|");
    return _myPath;
}



//  read and write the file list to the file

function fileIO(bReadOrWrite, fileURI, content)
{
    var bFlag = false;
    var fileTxt ;

    if(bReadOrWrite == "r")
    {
        fileTxt = FLfile.read(fileURI);
        if(fileTxt == null)
        {
            alert("fail to read the file" + fileURI);
        }
        //      alert(fileTxt);

        return fileTxt;
    }
    else if(bReadOrWrite == "w")
    {
        if ( ! (bFlag = FLfile.write(fileURI, content)))
        {
            alert("fail to write to " + fileURI);
        }
    }
    else if(bReadOrWrite == "w+")
    {
        if ( ! (bFlag = FLfile.write(fileURI, content, "append")))
        {
            alert("fail to append to " + fileURI);
        }
    }
    else
    {
        alert("the wrong way to call the function: fileIO!");
    }
    return bFlag;
}



//          open a fla document surely

function openDoc(_fileURI)
{
    var _doc;
    if(true == fl.fileExists(_fileURI))
    {
        _doc = fl.openDocument(_fileURI);
        //    alert("the file opened is : " + _fileURI);
        if(_fileURI != null)
        {
            ;
        }
    }
    else
    {
        alert(_fileURI + " dont exist!");
        _fileURI = null;
    }

    return _doc;
}



//  show the ascii code of the char in string

function showCode(strTest)
{
    var asciiQuene = "";
    for (var i = 0; i < strTest.length; i ++ )
    {
        asciiQuene += "0x" + strTest.charCodeAt(i);
    }
    //    alert("The string is :/n" + strTest + "/n/nthe ascii quene is :/n" + asciiQuene);
    return asciiQuene;
}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值