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?
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.
- < ?xml version="1.0" encoding="utf-8"?>
- <mx :WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
- <mx :Button x="209" y="166" label="Button" click="clickHandler()"/>
- </mx><mx :Script>
- < ![CDATA[
- private var codeTextFile:File;
- private var codeTextFileStream:FileStream;
- private var lineCount:uint = 0;
- private function clickHandler():void {
- codeTextFile = new File("file:///C:/source-code.txt")
- codeTextFileStream = new FileStream();
- codeTextFileStream.open(codeTextFile, FileMode.WRITE);
- var codeFile:File = new File("file:///C:/flex/apps");
- writeCodeTectFile(codeFile);
- codeTextFileStream.writeUTFBytes("================================\n");
- codeTextFileStream.writeUTFBytes("code line count : "+lineCount+"\n");
- codeTextFileStream.writeUTFBytes("================================\n");
- codeTextFileStream.close();
- }
- private function writeCodeTectFile(file:File):void {
- if(file.isDirectory) {
- var arr:Array = file.getDirectoryListing();
- for each(var f:File in arr) {
- writeCodeTectFile(f);
- }
- }
- else {
- var r:RegExp = /.+\.(as|mxml)/;
- if(r.test(file.name)) {
- var fs:FileStream = new FileStream();
- fs.open(file,FileMode.READ);
- var s:String = fs.readUTFBytes(fs.bytesAvailable);
- var r2:RegExp = /\n/g;
- lineCount += s.match(r2).length;
- codeTextFileStream.writeUTFBytes(s);
- fs.close();
- codeTextFileStream.writeUTFBytes("\n\n");
- }
- }
- }
- ]]>
- </mx>


Hi,
You can see another app doing the same and many other code stats here :
http://www.richanalysis.net/richcodeanalyser
Phiphou, from RichAnalysis