Using mixins
You can no longer attach a function to a class, unless that class has prior knowledge of that
function. For example, you can no longer do this:
UIComponent.prototype.doSomething = myFunction
or this:
dataGridInstance.doSomething = myFunction
You can still declare a Function type property on an Object and then supply an
implementation of that function later. For example:
class MyButton extends Button {
var doSomething:Function;
public function processInput(condition:Boolean):void {
if (condition)
doSomething();
}
}
and then:
var b:MyButton = new MyButton();
b.doSomething = function () { ... };
b.processInput(true);
You can also apply mixins to dynamic classes without their prior knowledge, as the following
example shows:
dynamic class MyButton extends Button {
...
}
and then:
// You can mix in any function onto an instance of a dynamic class:
var b:MyButton = new MyButton();
b.anyFunctionNameYouCanImagine = function () { ... };
// After it's added, you can call the function as follows:
b.anyFunctionNameYouCanImagine();
The only class in the Flex class library that is dynamic is the Object class. In most cases, you
must create your own class.
Using mixins
175
Need help?
Do you have a question about the FLEX 2-MIGRATING APPLICATIONS TO FLEX 2 and is the answer not in the manual?
Questions and answers