Archive for category Flex 3
SWCLib v1
SWC Interrogator
I’m in the process of creating a class and test class generator and needed a way of examining and listing Flash’s built in classes. I realised that I could do that by interrogating the SWC files in the /frameworks folder. Enter SWC Interrogator.
It’s pretty basic, to be honest. I’m using nochump’s ZipLib library to open .zip (SWC) files. In case you didn’t know (and how could you not :D), SWC files are basically .zip archives and can be treated as such. Anyway, I then extract the catalog.xml file from the SWC and parse the contents, creating several arraycollections containing classes, data types and attached files.
The application is based around the SWCReader class, which does pretty much what you’d expect it to.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | package com.atsog.SWC { import com.adobe.utils.StringUtil; import com.atsog.vo.SWC; import flash.filesystem.*; import flash.utils.ByteArray; import mx.collections.ArrayCollection; import nochump.util.zip.*; public class SWCReader { private var swc:SWC; public function openSWC(fileStream:FileStream):SWC { var zipFile:ZipFile = new ZipFile(fileStream); swc = new SWC(); for(var i:int = 0; i < zipFile.entries.length; i++) { var entry:ZipEntry = zipFile.entries[i]; if (entry.name == 'catalog.xml') { var data:ByteArray = zipFile.getInput(entry); swc = loadXML(new XML(data.toString())); } } return swc; } private function loadXML(xml:XML):SWC { var returnSWC:SWC = new SWC(); //get attributes var attributes:XMLList = xml.children(); for each (var attribute:XML in attributes) { //output trace trace('===='); trace(attribute.localName()); trace('===='); trace(' '); //find out which branch it is switch (attribute.localName()) { case 'versions': returnSWC.versionHistory = getVersionHistory(attribute); break; case 'components': returnSWC.components = getComponents(attribute.children()); break; case 'libraries': returnSWC.classNames = getLibraries(attribute.children().children()); break; case 'files': returnSWC.files = getFiles(attribute.children()); break; default: //otherwise do nothing break; } trace(' '); } return returnSWC; } private function getVersionHistory(list:XML):ArrayCollection { //gets the 'swc' and 'flex' version tags and put them in an arraycollection var versions:XMLList = list.children(); var versionHistory:ArrayCollection = new ArrayCollection(); for each(var i:Object in versions) { trace(i.@version); } versionHistory.addItem({name:'swc', version:versions[0].@version}); versionHistory.addItem({name:'flex', version:versions[1].@version}); return versionHistory; } private function getLibraries(scripts:XMLList):ArrayCollection { //get the 'script' library tags, cleans up the text and extracts the class name from the package. //returns an arraycollection of classes var classNames:ArrayCollection = new ArrayCollection(); for each (var script:XML in scripts) { trace(script.@name); //clean up '/' for package and class var utClass:String = script.@name; var utClassArray:Array = utClass.split('/'); var classVO:Object = new Object(); classVO.packageName = StringUtil.replace(utClass, '/', '.'); classVO.className = utClassArray[utClassArray.length-1]; classNames.addItem(classVO); } return classNames; } private function getComponents(list:XMLList):ArrayCollection { //returns an arraycollection of component (primitive data types) var components:ArrayCollection = new ArrayCollection(); for each (var component:XML in list) { trace(component.@className); components.addItem({name: component.@className}); } return components; } private function getFiles(list:XMLList):ArrayCollection { //returns a list of files var files:ArrayCollection = new ArrayCollection(); for each (var file:XML in list) { trace(file.@name); files.addItem({name: file.@name}); } return files; } public function get classes():ArrayCollection { return swc.classNames; } public function get components():ArrayCollection { return swc.components; } public function get versionHistory():ArrayCollection { return swc.versionHistory; } public function get files():ArrayCollection { return swc.files; } } } |
You can download it here