摘自:http://www.darronschall.com/weblog/archives/000126.cfm
// 1) create a blank fla, drag a v2 button to the
// stage then delete the button instance so that
// the button only resides in the library.
// 2) paste this code on frame 1 and test movie
import mx.utils.Delegate;
import mx.controls.Button;
function init() {
// create and place our buttons
createClassObject(Button, "btn1", 1, {label:"plus 1"});
createClassObject(Button, "btn2", 2, {label:"plus 5", _y: btn1._y+btn1.height});
// both buttons use the same onIncrement event
// handler - but the handler behaves differently
// based on the step value set
var f = Delegate.create(this, onIncrement);
f.step = 1; // btn1 steps up by 1
btn1.addEventListener("click", f);
f = Delegate.create(this, onIncrement);
f.step = 5; // btn2 setps up by 5
btn2.addEventListener("click", f);
// initialize our running total
total = 0;
}
// generic increment function used as
// event handler for the buttons
function onIncrement() {
// grab the step property from the
// delegate function we created, and use
// that as the increment value
total += arguments.caller.step;
trace(total);
}
init();
回复Comments
作者:
{commentrecontent}