Here's how I would define your MenuItem class
// ............................................... MenuItem Object
var MenuItem = Path.extend({
enumerable: true, // makes additional methods visible
_class: 'MenuItem', // just to keep things straight
_isSelected: false, // toggle variable
// internal initialization function, from Base
initialize: function MenuItem(arg0, arg1, arg2) {
var that = this;
// create button
this.path = new Path.Rectangle({
position: arg0 || new Point(0,0),
size: arg1 || [200, 50]
});
this.path.fillColor = '#333333';
// create group
this.me.addChild( this.path );
// create label
this.label = new PointText(this.path.position);
this.label.fillColor = 'white';
this.label.content = arg2 || '';
this.label.justification = 'center';
this.me.addChild( this.label );
// define event(s)
this.path.on('click', function(){
that._isSelected = !that._isSelected;
if( that._isSelected ) {
that.deselect();
}
else {
that.select();
}
});
return this;
},
// additional methods
select: function() {
this.path.fillColor = 'blue';
},
deselect: function() {
this.path.fillColor = '#333333';
},
setLabel: function(label) {
this.label.content = label;
}
});