2. What it AS3Commons?
• Open source community project
• Contains several ActionScript 3.0 libraries
• Minimal dependencies between libraries: pick
what you need
• No Flex dependencies!
• See Apache Commons
3. Why AS3Commons?
• Central place for AS3 utility libraries
• Assure quality of libraries
• Unit tested
• Started with core parts of the Spring
ActionScript project
6. AS3Commons Logging
• Logging API abstraction over existing logging
APIs
• Wrappers for Flex logger, etc
• Write your own logger/wrapper: SOS, De
Monster Debugger, ...
7. AS3Commons Logging - Example
var logger:ILogger = LoggerFactory.getClassLogger(MyClass);
logger.debug(“A log statement: {0} {1}”, myVar, myVar2);
logger.info...
logger.warn...
logger.error...
logger.fatal...
Writes to standard ouput console using trace()
You can also log objects (Monster Debugger)
8. AS3Commons Logging - Example
// disable logging
LoggerFactory.loggerFactory = null;
OR
// redirect logging to Flex logger
LoggerFactory.loggerFactory = new FlexLoggerFactory();
var traceTarget:TraceTarget = new TraceTarget();
Log.addTarget(traceTarget);
10. AS3Commons Lang
• ArrayUtils, ObjectUtils, StringUtils, ...
• Basic support for missing AS3 concepts:
equality, string builders, comparing, enums,
assertions, etc
• Enums: allows mapping to java enums
through BlazeDS
• Assertions: fail fast
11. AS3Commons Lang – Enum
public class Color extends Enum {
public static const RED:Color = new Color(“RED”);
public static const GREEN:Color = new Color(“GREEN”);
public static const BLUE:Color = new Color(“BLUE”);
public function Color(name:String) {
super(name);
}
}
12. AS3Commons Lang – Equals
public function equals(other:*):Boolean {
if (this === other) {
return true;
}
if (!(other is ThisClass)) {
return false;
}
var other:ThisClass = ThisClass(other);
return new EqualsBuilder()
.append(prop, other.prop)
.equals;
}
14. AS3Commons Reflect
• Get class/object information at runtime
• Clear API on top of describeType, no XML
15. AS3Commons Reflect - Example
var type:Type = Type.forClass(String);
for each (var method:Method in type.methods) {
// do something really useful with method
// e.g. Invoke method dynamically
}
OR
var type:Type = Type.forInstance(myString);
var type:Type = Type.forName(“String”);
19. AS3Commons Concurrency
• Pseudo threading
• Break up CPU intensive operations in
“Runnables”
• Execute these runnables without blocking the
UI (or at least not completely)
• Asynchronous
23. What it is
• Reads ABC bytecode and converts it into an
object model
• This object model can be queried for all sorts
of interesting data
• It can generate ABC bytecode and load it into
the VM
27. Metadata lookup
var metaDataLookup:Object =
ByteCodeType.metaDataLookupFromLoader(loader);
var definitionNames:Array = metaDataLookup['Mixin'];
Spring ActionScript’s Class scanning system uses
this.
28. Class generation
var abcBuilder:IAbcBuilder = new AbcBuilder();
var packageBuilder:IPackageBuilder =
abcBuilder.definePackage("com.classes.generated");
var classBuilder:IClassBuilder =
packageBuilder.defineClass("RuntimeClass");
32. Loading the class into the VM
abcBuilder.addEventListener(Event.COMPLETE,
loadedHandler);
abcBuilder.addEventListener(IOErrorEvent.IO_ERROR,
errorHandler);
abcBuilder.addEventListener(IOErrorEvent.VERIFY_ERROR,
errorHandler);
abcBuilder.buildAndLoad();
33. Instantiating the class
var className:String = “com.generated.RuntimeClass”;
var dom:ApplicationDomain = ApplicationDomain.currentDomain;
var clazz:Class = dom.getDefinition(className) as Class;
var instance:Object = new clazz();
var i:int = instance.multiplyByHundred(10);
// i == 1000
34. The road ahead…
• Manipulation of existing classes
• Foundation for AS3Commons Aspect
• All sorts of other goodies