Flex SWC class parser
Quick tool that prints out all the available classes exported by a SWC file.
Usage swfinfo.py
#!/usr/bin/python
# Filename: swc-info.pl
# Author : Lokkju Brennr <lokkju@lokkju.com>
# License : GPL
# Copyright 2010
import sys
import getopt
import zipfile
from xml.etree import ElementTree
def usage():
print "%s <swcfile>" % (sys.argv[0])
print " Prints all classes exported by the provided swc(s). Supports wildcard globbing"
sys.exit(2)
def main():
# parse command line options
if len(sys.argv) < 2:
usage()
files = sys.argv[1:]
for swcfile in files:
z = zipfile.ZipFile(swcfile,'r')
catalog = z.open("catalog.xml")
catalogxml = catalog.read()
catalog.close()
z.close()
tree = ElementTree.XML(catalogxml)
defs = tree.findall(".//{http://www.adobe.com/flash/swccatalog/9}def")
for d in defs:
id = d.attrib.get("id")
type = d.attrib.get("type")
if type is None:
print "%s:%s" % (swcfile,id)
if __name__ == "__main__":
main()
Supporting dynamic FlexFileSets in Flex’s compc and mxmlc Ant tasks
If you are using the mxmlc and compc tasks in Ant to compile flex code, there is no documented way to make the fileset-like children accept a dynamic include pattern - that is, one you set based on conditionals.
In my case, I need to have a list of included libraries in my build.properties, and only include those ones in my compc task. The solution is to use patternsets and a custom ant macro. See the source below, but essentially you do the following:
- Create a new patternset, assigning it an id
- Use the append.to.patternset macro to add a new patternset for each pattern in your list of library patterns (as defined in you build.properties, or dynamically, or...)
- assign that patternset to the library-path of compc
Important: All the patterns must decend from the same root directory as set in the library-path. If you need multiple root directories, you must use multiple library-path directives and multiple patternset refids.
build.xml:
<?xml version="1.0" encoding="utf-8"?>
<project name="My Component Builder" basedir=".">
<taskdef resource="flexTasks.tasks" classpath="${basedir}/flexTasks/lib/flexTasks.jar" />
<property file="build.properties"/>
<property name="FLEX_HOME" value="C:/flex/sdk"/>
<property name="DEPLOY_DIR" value="c:/jrun4/servers/default/default-war"/>
<property name="COMPONENT_ROOT" value="components"/>
<macrodef name="append.to.patternset">
<attribute name="patternset"/>
<element name="nested" optional="yes" implicit="true"/>
<sequential>
<patternset id="tmp">
<patternset refid="@{patternset}"/>
<nested/>
</patternset>
<patternset id="@{patternset}"><patternset refid="tmp"/></patternset>
<patternset id="tmp"/>
</sequential>
</macrodef>
<patternset id="compc.library-path" />
<for list="${compc.libraries}" param="lib">
<sequential>
<append.to.patternset patternset="compc.library-path">
<patternset>
<include name="@{lib}" />
</patternset>
</append.to.patternset>
</sequential>
</for>
<target name="main">
<compc
output="${DEPLOY_DIR}/MyComps.swc"
include-classes="custom.MyButton custom.MyLabel">
<source-path path-element="${basedir}/components"/>
<include-file name="f1-1.jpg" path="assets/images/f1-1.jpg"/>
<include-file name="main.css" path="assets/css/main.css"/>
<library-path append="true" dir="${compc.libdir}">
<patternset refid="compc.library-path" />
</library-path>
</compc>
</target>
<target name="clean">
<delete>
<fileset dir="${DEPLOY_DIR}" includes="MyComps.swc"/>
</delete>
</target>
</project>
build.properties:
compc.libdir=${rootdir}/libs/
compc.libraries=lib1.swc,plib*.swc,**/type.swc
