Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/SimonRichardson/as3-mixins
Create real mixins using bytecode injection at runtime.
https://github.com/SimonRichardson/as3-mixins
Last synced: about 2 months ago
JSON representation
Create real mixins using bytecode injection at runtime.
- Host: GitHub
- URL: https://github.com/SimonRichardson/as3-mixins
- Owner: SimonRichardson
- License: mit
- Archived: true
- Created: 2011-04-18T12:37:21.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2011-09-15T14:58:27.000Z (over 13 years ago)
- Last Synced: 2024-08-04T05:04:32.695Z (5 months ago)
- Language: ActionScript
- Homepage: http://www.simonrichardson.info
- Size: 1.8 MB
- Stars: 28
- Watchers: 3
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.textile
- License: MIT-LICENSE.txt
Awesome Lists containing this project
- awesome-actionscript-sorted - as3-mixins - Create real mixins using bytecode injection at runtime. (Utilities / Dependency Injection)
README
h1. AS3-Mixins
AS3-Mixin is a project to enable runtime bytecode generation of mixins. The project uses a strict
typed setup to mix the interfaces (known as definitions) and concrete classes (known as
implementations).AS3-Mixin uses the "MIT":http://en.wikipedia.org/wiki/MIT_License license.
h2. Performance
To enable AS3-Mixin to work we have to create a series of SWF's at runtime which will then be
injected into your application SWF. This obviously has a hit when creating the application, but
once the implementation has been created, it is relatively performance free to create new
instances of the implementation (relatively meaning that it has to delegate the creation of the
instance and will be slower than instantiating it by hand).h2. Thanks
The inspiration for this was "AS3-retrofit":https://github.com/brianheylin/as3-retrofit, although
I've removed quite a lot from that. Also there are subtle changes through out, but there could
be a time where I move this back to AS3-retrofit, although I think AS3-Mixins sounds better.AS3-Mixin uses
* "AS3-Signals":https://github.com/robertpenner/as3-signals
* "FLemit":http://code.google.com/p/flemit/
* "ASunit":https://github.com/patternpark/asunith2. Example
To create a AS3-Mixin you have to define a series of definitions and implementations.
Create a definition IPosition.as in this case it's just an interface.
package org.osflash.mixins.support
{
public interface IPosition
{
function get x() : int;
function set x(value : int) : void;
function get y() : int;
function set y(value : int) : void;
}
}Create a implementation PositionImpl.as.
package org.osflash.mixins.support.impl
{
import org.osflash.mixins.support.IPosition;
public final class PositionImpl implements IPosition
{
private var _x : int;
private var _y : int;public function PositionImpl()
{
_x = 0;
_y = 0;
}
public function get x() : int { return _x; }public function set x(value : int) : void { _x = value; }
public function get y() : int { return _y; }
public function set y(value : int) : void { _y = value; }
}
}Then finally make the definitive implementation that's going to hold your mixin together (note:
I've also added a ISize definition and SizeImpl to make it a true mixin).
package org.osflash.mixins.support
{
public interface ISquare extends ISize, IPosition
{
}
}Then to sew it altogether:
var mixin : IMixin = new Mixin();
mixin.add(IPosition, PositionImpl);
mixin.add(ISize, SizeImpl);
mixin.define(ISquare);
mixin.generate().completedSignal.add(function(mixin:Mixin): void
{
var square : ISquare = mixin.create(ISquare);
trace("I have a square!");
});