Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

SimonRichardson/as3-mixins

Repository files navigation

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 license.

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).

Thanks

The inspiration for this was 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

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!");
                                        });

About

Create real mixins using bytecode injection at runtime.

Resources

License

Stars

Watchers

Forks

Packages

No packages published