| Package | org.as3commons.bytecode.emit.impl |
| Class | public class AbcBuilder |
| Inheritance | AbcBuilder flash.events.EventDispatcher |
| Implements | IAbcBuilder |
AbcBuilder is the main entry point for the emit API. Here is
an example of how to generate a simple class:
function generateClass():void {
var abcBuilder:IAbcBuilder = new AbcBuilder();
var classBuilder:IClassBuilder = abcBuilder.definePackage("com.classes.generated").defineClass("MyGeneratedClass");
classBuilder.defineProperty("myProperty", "String", "default value");
classBuilder.defineAccessor("myOtherProperty", "int", 10).access = AccessorAccess.READ_ONLY;
abcBuilder.addEventListener(Event.COMPLETE, completeHandler);
abcBuilder.buildAndLoad(); //loads the generated class into the current application domain
}
function completeHandler(event:Event):void {
var clazz:Class = ApplicationDomain.currentDomain.getDefinition("com.classes.generated.MyGeneratedClass") as Class;
var instance:Object = new class();
var propertyValue:String = instance.myProperty;
var otherPropertyValue:int = instance.myOtherProperty;
//propertyValue == "default value"
//otherPropertyValue == 10
instance.myOtherProperty = 20; //ERROR! Accessor is read-only (getter)
}
function generateClass():void {
var abcBuilder:IAbcBuilder = new AbcBuilder();
var classBuilder:IClassBuilder = abcBuilder.definePackage("com.classes.generated").defineClass("MyGeneratedClass");
var methodBuilder:IMethodBuilder = classBuilder.defineMethod("multiplyByHundred");
methodBuilder.returnType("int");
methodBuilder.defineArgument("int");
methodBuilder.addOpcode(Opcode.getlocal_0)
.addOpcode(Opcode.pushscope)
.addOpcode(Opcode.getlocal_1)
.addOpcode(Opcode.pushint, [100])
.addOpcode(Opcode.multiply)
.addOpcode(Opcode.setlocal_1)
.addOpcode(Opcode.getlocal_1)
.addOpcode(Opcode.returnvalue);
abcBuilder.addEventListener(Event.COMPLETE, completeHandler);
abcBuilder.buildAndLoad(); //loads the generated class into the current application domain
}
function completeHandler(event:Event):void {
var clazz:Class = ApplicationDomain.currentDomain.getDefinition("com.classes.generated.MyGeneratedClass") as Class;
var instance:Object = new class();
var i:int = instance.multiplyByHundred(10);
// i == 1000
}
| Property | Defined By | ||
|---|---|---|---|
| loader : AbcClassLoader [read-only]
Internal AbcClassLoader instance used by the buildAndLoad() method. | AbcBuilder | ||
| serializer : AbcSerializer [read-only]
Internal AbcSerializer instance used by the buildAndExport() method. | AbcBuilder | ||
| Method | Defined By | ||
|---|---|---|---|
AbcBuilder(abcFile:AbcFile = null)
Creates a new AbcBuilder instance. | AbcBuilder | ||
Builds an AbcFile using the previously defined IPackageBuilder instances. | AbcBuilder | ||
buildAndExport(applicationDomain:ApplicationDomain = null):ByteArray
Builds, serializes and wraps the AbcFile in a SWF, the resulting ByteArray can be saved to
disk as a .swf file for later use. | AbcBuilder | ||
buildAndLoad(applicationDomain:ApplicationDomain = null, newApplicationDomain:ApplicationDomain = null):AbcFile
Builds the AbcFile and immediately loads it into the AVM. | AbcBuilder | ||
defineClass(fullName:String, superClassName:String = null):IClassBuilder
Creates an IClassBuilder instance for the specified fuly qualified class name and super class name. | AbcBuilder | ||
defineInterface(fullName:String, superInterfaceNames:Array = null):IInterfaceBuilder
Creates an IInterfaceBuilder instance for the specified fully qualified interface name and super interface names. | AbcBuilder | ||
defineNamespace(fullScopeName:String, URI:String):INamespaceBuilder | AbcBuilder | ||
definePackage(name:String):IPackageBuilder
If the specified package name already exists, the exisiting IPackageBuilder
will be returned instead of a new instance.
Creates an IPackageBuilder instance for the specified package name. | AbcBuilder | ||
| Method | Defined By | ||
|---|---|---|---|
addAbcObjects(instances:*, abcFile:AbcFile, applicationDomain:ApplicationDomain, index:uint):uint | AbcBuilder | ||
Adds the specified ClassInfo and its constructor MethodInfo to the specified AbcFile. | AbcBuilder | ||
Adds the specified InstanceInfo and its constructor MethodInfo to the specified AbcFile. | AbcBuilder | ||
Adds the specified MethodInfo, its associated MethodBody and, if present,
its associated Metadata entries to the specified AbcFile. | AbcBuilder | ||
| AbcBuilder | |||
addScriptInfo(abcFile:AbcFile, instanceInfo:InstanceInfo, applicationDomain:ApplicationDomain, index:uint):void
Creates a ScriptInfo instance based on the specified InstanceInfo and adds it and its constructor
MethodInfo to the specified AbcFile. | AbcBuilder | ||
classNotFoundHandler(event:ExtendedClassesNotFoundError):void | AbcBuilder | ||
createClassScriptInfo(className:String, superClass:BaseMultiname, classInfo:ClassInfo, applicationDomain:ApplicationDomain, index:uint, isInterface:Boolean):ScriptInfo
Creates a ScriptInfo instance based on the specified InstanceInfo. | AbcBuilder | ||
createClassScriptInitializer(className:String, superClass:BaseMultiname, classInfo:ClassInfo, applicationDomain:ApplicationDomain):MethodInfo
Creates a MethodInfo instance that represents the initializer method for a ScriptInfo. | AbcBuilder | ||
Creates a ClassTrait instance for the specified class name and class index. | AbcBuilder | ||
| AbcBuilder | |||
| AbcBuilder | |||
| AbcBuilder | |||
extractExtendedClasses(superClassname:String, applicationDomain:ApplicationDomain):Array | AbcBuilder | ||
redispatch(event:Event):void
Redispatches the specified AbcClassLoader Event. | AbcBuilder | ||
| Event | Summary | Defined By | ||
|---|---|---|---|---|
| Dispatched when the class loader has finished loading the SWF/ABC bytecode in the Flash Player/AVM. | AbcBuilder | |||
| Dispatched when the class loader has encountered an IO related error. | AbcBuilder | |||
| Dispatched when the class loader has encountered a SWF verification error. | AbcBuilder | |||
| loader | property |
loader:AbcClassLoader [read-only]
Internal AbcClassLoader instance used by the buildAndLoad() method.
protected function get loader():AbcClassLoader| serializer | property |
serializer:AbcSerializer [read-only]
Internal AbcSerializer instance used by the buildAndExport() method.
protected function get serializer():AbcSerializer| AbcBuilder | () | Constructor |
public function AbcBuilder(abcFile:AbcFile = null)
Creates a new AbcBuilder instance.
abcFile:AbcFile (default = null) |
| addAbcObjects | () | method |
protected function addAbcObjects(instances:*, abcFile:AbcFile, applicationDomain:ApplicationDomain, index:uint):uint
Parameters
instances:* — Array of builder objects that represent the various elements to be added to the AbcFile.
| |
abcFile:AbcFile — The AbcFile that will be populated with the builder results.
| |
applicationDomain:ApplicationDomain — The ApplicationDomain used to lookup superclasses.
| |
index:uint — The current class index in the AbcFile.
|
uint — The current class index in the AbcFile.
|
| addClassInfo | () | method |
protected function addClassInfo(abcFile:AbcFile, classInfo:ClassInfo):void
Adds the specified ClassInfo and its constructor MethodInfo to the specified AbcFile.
Parameters
abcFile:AbcFile — The specified AbcFile.
| |
classInfo:ClassInfo — The specified ClassInfo.
|
| addInstanceInfo | () | method |
protected function addInstanceInfo(abcFile:AbcFile, instanceInfo:InstanceInfo):void
Adds the specified InstanceInfo and its constructor MethodInfo to the specified AbcFile.
Parameters
abcFile:AbcFile — The specified AbcFile.
| |
instanceInfo:InstanceInfo — The specified InstanceInfo.
|
| addMethodInfo | () | method |
protected function addMethodInfo(abcFile:AbcFile, methodInfo:MethodInfo):void
Adds the specified MethodInfo, its associated MethodBody and, if present,
its associated Metadata entries to the specified AbcFile.
Parameters
abcFile:AbcFile — the specified AbcFile.
| |
methodInfo:MethodInfo — the specified MethodInfo.
|
| addNamespace | () | method |
protected function addNamespace(abcFile:AbcFile, slot:SlotOrConstantTrait):voidParameters
abcFile:AbcFile | |
slot:SlotOrConstantTrait |
| addScriptInfo | () | method |
protected function addScriptInfo(abcFile:AbcFile, instanceInfo:InstanceInfo, applicationDomain:ApplicationDomain, index:uint):void
Creates a ScriptInfo instance based on the specified InstanceInfo and adds it and its constructor
MethodInfo to the specified AbcFile.
Parameters
abcFile:AbcFile — The specified AbcFile.
| |
instanceInfo:InstanceInfo — The specified InstanceInfo.
| |
applicationDomain:ApplicationDomain — The ApplicationDomain used to lookup superclasses.
| |
index:uint — The current class index in the AbcFile.
|
| build | () | method |
public function build(applicationDomain:ApplicationDomain = null):AbcFile
Builds an AbcFile using the previously defined IPackageBuilder instances.
Parameters
applicationDomain:ApplicationDomain (default = null) — The applicationDomain that has access to the super classes that are defined
for any classes defined in the AbcFile, defaults to ApplicationDomain.currentDomain.
|
AbcFile — The created AbcFile.
|
| buildAndExport | () | method |
public function buildAndExport(applicationDomain:ApplicationDomain = null):ByteArray
Builds, serializes and wraps the AbcFile in a SWF, the resulting ByteArray can be saved to
disk as a .swf file for later use.
Parameters
applicationDomain:ApplicationDomain (default = null) — The applicationDomain that has access to the super classes that are defined.
|
ByteArray — The ByteArray containing the serialized AbcFile wrapped inside a SWF.
|
| buildAndLoad | () | method |
public function buildAndLoad(applicationDomain:ApplicationDomain = null, newApplicationDomain:ApplicationDomain = null):AbcFile
Builds the AbcFile and immediately loads it into the AVM.
This behaviour is asynchronous, so be sure to listen for the Event.COMPLETE, IOErrorEvent.IO_ERROR and
IOErrorEvent.VERIFY_ERROR on the current IAbcBuilder.
Once the Event.COMPLETE event has been fired it will be possible to retrieve a reference to the generated classes through the specified application
domain, like this:
var cls:Class = applicationDomain.getDefinition("com.myclasses.MyGeneratedClass") as Class
Parameters
applicationDomain:ApplicationDomain (default = null) — The applicationDomain that has access to the super classes that are defined
for any classes defined in the AbcFile, defaults to ApplicationDomain.currentDomain.
| |
newApplicationDomain:ApplicationDomain (default = null) — The ApplicationDomain in which the newly created AbcFile will be loaded,
defaults to ApplicationDomain.currentDomain.
|
AbcFile — The created AbcFile.
|
| classNotFoundHandler | () | method |
protected function classNotFoundHandler(event:ExtendedClassesNotFoundError):void
Parameters
event:ExtendedClassesNotFoundError |
| createClassScriptInfo | () | method |
protected function createClassScriptInfo(className:String, superClass:BaseMultiname, classInfo:ClassInfo, applicationDomain:ApplicationDomain, index:uint, isInterface:Boolean):ScriptInfo
Creates a ScriptInfo instance based on the specified InstanceInfo.
Parameters
className:String — The class name of the generated class
| |
superClass:BaseMultiname — A BaseMultiName representing the super class.
| |
classInfo:ClassInfo — The ClassInfo associated with the new ScriptInfo.
| |
applicationDomain:ApplicationDomain — The ApplicationDomain used to lookup superclasses.
| |
index:uint — The current class index in the AbcFile.
| |
isInterface:Boolean |
ScriptInfo — The new ScriptInfo instance.
|
| createClassScriptInitializer | () | method |
protected function createClassScriptInitializer(className:String, superClass:BaseMultiname, classInfo:ClassInfo, applicationDomain:ApplicationDomain):MethodInfo
Creates a MethodInfo instance that represents the initializer method for a ScriptInfo.
Parameters
className:String — The class name associated with the ScriptInfo.
| |
superClass:BaseMultiname — The super class name associated with the ScriptInfo.
| |
classInfo:ClassInfo — The ClassInfo name associated with the ScriptInfo.
| |
applicationDomain:ApplicationDomain — The ApplicationDomain used to lookup the superClass.
|
MethodInfo — The new MethodInfo instance.
|
| createClassTrait | () | method |
protected function createClassTrait(className:String, index:uint, classInfo:ClassInfo):ClassTrait
Creates a ClassTrait instance for the specified class name and class index.
Parameters
className:String — The specified class name.
| |
index:uint — The current class index in the AbcFile.
| |
classInfo:ClassInfo |
ClassTrait — the new ClassTrait.
|
| createInterfaceScriptInitializer | () | method |
protected function createInterfaceScriptInitializer(className:String, classInfo:ClassInfo):MethodInfoParameters
className:String | |
classInfo:ClassInfo |
MethodInfo |
| createNamespaceScriptInfo | () | method |
| createNamespaceScriptInitializer | () | method |
| defineClass | () | method |
public function defineClass(fullName:String, superClassName:String = null):IClassBuilder
Creates an IClassBuilder instance for the specified fuly qualified class name and super class name.
Parameters
fullName:String — The fully qualified name of the new class. I.e. com.myclasses.MyGeneratedClass.
| |
superClassName:String (default = null) — The fully qualified super class name. I.e. mx.events.FlexEvent, defaults to Object.
|
IClassBuilder — The specified IClassBuilder instance.
|
| defineInterface | () | method |
public function defineInterface(fullName:String, superInterfaceNames:Array = null):IInterfaceBuilder
Creates an IInterfaceBuilder instance for the specified fully qualified interface name and super interface names.
Parameters
fullName:String — The fully qualified name of the new interface. I.e. com.myinterfaces.IMyGeneratedInterface.
| |
superInterfaceNames:Array (default = null) — The fully qualified super interface names. I.e. mx.styles.IStyleClient.
|
IInterfaceBuilder — The specified IInterfaceBuilder instance.
|
| defineNamespace | () | method |
public function defineNamespace(fullScopeName:String, URI:String):INamespaceBuilder
Parameters
fullScopeName:String | |
URI:String |
INamespaceBuilder —
|
| definePackage | () | method |
public function definePackage(name:String):IPackageBuilder
If the specified package name already exists, the exisiting IPackageBuilder
will be returned instead of a new instance.
IPackageBuilder instance for the specified package name.
An example of a package name: com.myclasses.test
Parameters
name:String — The specified package name
|
IPackageBuilder — The specified IPackageBuilder instance.
|
| extractExtendedClasses | () | method |
protected function extractExtendedClasses(superClassname:String, applicationDomain:ApplicationDomain):ArrayParameters
superClassname:String | |
applicationDomain:ApplicationDomain |
Array |
| redispatch | () | method |
protected function redispatch(event:Event):void
Redispatches the specified AbcClassLoader Event.
Parameters
event:Event — The specified AbcClassLoader Event.
|
| complete | Event |
flash.events.Eventflash.events.Event.COMPLETEDispatched when the class loader has finished loading the SWF/ABC bytecode in the Flash Player/AVM.
| ioError | Event |
flash.events.IOErrorEventflash.events.IOErrorEvent.IO_ERRORDispatched when the class loader has encountered an IO related error.
| verifyError | Event |
flash.events.IOErrorEventflash.events.IOErrorEvent.VERIFY_ERRORDispatched when the class loader has encountered a SWF verification error.