CoreMedia Content Cloud v11 Upgrade Guide / Version 2110
Table Of Contents
In ActionScript, a class can only extend one other class, but it can implement multiple interfaces. So for a class
to be used as a mixin, we extract an interface from that class with a custom ActionScript annotation
[Mixin("
fully-qualified name of mixin implementation class")]
. Any
class MixinClient
that implements such an interface acme.IMyMixin
annotated with
[Mixin("acme.MyMixin")]
becomes a mixin client class, in other words, MyMixin
is mixed
into MixinClient
. Because ActionScript tools (asdoc, IDEA) do not know of this magic annotation,
MixinClient
also must implement all IMyMixin
methods to comply with ActionScript semantics.
As we do not really want to implement these methods, we just declare them, using the
native
keyword.
// ./acme/IMyMixin.as package acme { [Mixin("acme.MyMixin")] public interface IMyMixin { [Bindable] function get mixinConfig(): String; [Bindable] function set mixinConfig(value: String): void; function doSomething(): Number; } } // ./acme/MyMixin.as package acme { public class MyMixin implements IMyMixin { private var _mixinConfig: String = ""; [Bindable] public function get mixinConfig(): String { return _mixinConfig; } [Bindable] public function set mixinConfig(value: String): void { _mixinConfig = value; } public function doSomething(): Number { return _mixinConfig.length; } } } // ./MixinClient.as import acme.IMyMixin; import ext.Component; public class MixinClient extends Component implements IMyMixin { [Bindable] public native function get mixinConfig(): String; [Bindable] public native function set mixinConfig(value: String): void; public native function doSomething(): Number; public function MixinClient(config: Object = null) { super(config); doSomething(); } }
Example 7.3. Mixin in ActionScript example