PDA

View Full Version : macromedia style- change/click handler


heyder
04-12-2003, 08:40 PM
How can I set-up an event handler like on some of the macromedia components.

ie.. a user defined function recieves a callback from the component when clicked.

I found the code below but I not sure how to get it working with a new component (I have listed what I have tried to this point)



//put this inside the component

ComponentClass.prototype.setClickHandler = function(chng,obj) {
this.handlerObj = (arguments.length<2) ? this._parent : obj;
this.clickHandler = chng;
};

ComponentClass.prototype.executeCallBack = function() {
this.handlerObj[this.clickHandler](this);
};

//added this code to main timeline
componentInstanceName.setClickHandler("myClick", _root);


function myClick(component) {
trace (component);
}


I know I missing some stuff but not sure what...

tyard
04-13-2003, 04:29 AM
Looks good to me. And you have set up an onPress or onRelease somewhere that will call the executeCallBack?

heyder
04-13-2003, 06:24 PM
How does that part work?

componentname.onPress=function(){
myClick();
}

tyard
04-13-2003, 09:09 PM
Well, it depends on how you've set it up. Normally, you might do it in the component's init method (or whatever initialization script you have for the Class):


ComponentClass.prototype.init = function() {
// other code
this.onPress = this.executeCallback;
};

heyder
04-15-2003, 01:05 AM
Great, thanks. Makes sense now.