As a programmer, project manager or a customer, we need an overview of a project source code. There are so many tools which can help us quickly and easily get a report on source code in some programming languages such as C/C++, Java, PHP etc.

As a adobe AIR programmer, mayby you wanna make a Source Line Counter by yourself, you can know the line of *.mxml and *.as. How can we build it?

www_donotyet_com_Adobe-AIR-Source-Line-Count-with-source-code

Following is the source code on how to count the  *.mxml and *.as. Only one source file be support in this sample but you can easily modify it to support mutli-files like a full AIR project.

  1. < ?xml version="1.0" encoding="utf-8"?>
  2. <mx :WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
  3.     <mx :Button x="209" y="166" label="Button" click="clickHandler()"/>
  4.     </mx><mx :Script>
  5.         < ![CDATA[
  6.             private var codeTextFile:File;
  7.             private var codeTextFileStream:FileStream;
  8.             private var lineCount:uint = 0;
  9.             private function clickHandler():void {
  10.                 codeTextFile = new File("file:///C:/source-code.txt")
  11.                 codeTextFileStream = new FileStream();
  12.                 codeTextFileStream.open(codeTextFile, FileMode.WRITE);
  13.  
  14.                 var codeFile:File = new File("file:///C:/flex/apps");
  15.                 writeCodeTectFile(codeFile);
  16.                 codeTextFileStream.writeUTFBytes("================================\n");
  17.                 codeTextFileStream.writeUTFBytes("code line count : "+lineCount+"\n");
  18.                 codeTextFileStream.writeUTFBytes("================================\n");
  19.                 codeTextFileStream.close();
  20.             }
  21.             private function writeCodeTectFile(file:File):void {
  22.                 if(file.isDirectory) {
  23.                     var arr:Array = file.getDirectoryListing();
  24.                     for each(var f:File in arr) {
  25.                         writeCodeTectFile(f);
  26.                     }
  27.                 }
  28.                 else {
  29.                     var r:RegExp = /.+\.(as|mxml)/;
  30.                     if(r.test(file.name)) {
  31.                         var fs:FileStream = new FileStream();
  32.                         fs.open(file,FileMode.READ);
  33.                         var s:String = fs.readUTFBytes(fs.bytesAvailable);
  34.                         var r2:RegExp = /\n/g;
  35.                         lineCount += s.match(r2).length;
  36.                         codeTextFileStream.writeUTFBytes(s);
  37.                         fs.close();
  38.                         codeTextFileStream.writeUTFBytes("\n\n");
  39.                     }
  40.                 }
  41.             }
  42.         ]]>
  43.     </mx>

Related Posts