(dés)activer les événements souris dans un composant
1 réponse
bastbast webforumsuser
bonjour.
j'ai un composant palette de couleurs dont je souhaite désactiver puis réactiver, ainsi de suite, l'écoute des événements souris lorsque l'on passe dessus. j'ai essayer de transformer un clip de ce composant en bouton et de faire un theComponant.theClip.enabled = false, mais ça n'a pas marché.
en fait, j'aimerais pouvoir définir une méthode visible depuis l'extérieur du composant, de manière à pouvoir ainsi autoriser ou non la gestion des événements souris dans le composant. en gros, j'aimerais un appel du type theComponant.theClip.setEvtsEnabled(true); ou theComponant.theClip.setEvtsEnabled(false); dans le programme principal.
j'aimerais donc bien activer/désactiver à volonté toute la gestion des événments qui correspondent au ligne commençant par this.pane.on.... pour plus de détails, le composant est visible ici :
/*
+---------------------+
| etf std color class |
| +------------------------+
+--| etf color picker class |
+------------------------+
=================================
(c) 2002 by martin naas, etf.ch
=================================
v.1.1 :: 8-8-2002
=================================
*/
// >> constructor
function etfColorPickerClass ()
{
this.init ();
}
// inheritance
etfColorPickerClass.prototype = new etfStdColorClass ();
Object.registerClass ("etfColorPickerSymbol", etfColorPickerClass);
etfColorPickerClass.prototype.init = function ()
{
// mc's
this.pickerMC = this.pane.pickerMC;
// init ranges for this pane
var red_range = new etfRangeClass (0, 21.5);
var yellow_range = new etfRangeClass (21.5, 47.5);
var green_range = new etfRangeClass (47.5, 65);
var cyan_range = new etfRangeClass (65, 86.5);
var blue_range = new etfRangeClass (86.5, 108);
var magenta_range = new etfRangeClass (108, 130);
var white_range = new etfRangeClass (0, 20);
var black_range = new etfRangeClass (20, 40);
// init the calculate class
this.calcClass = new etfColorPickerCalcClass (
0,
red_range,
yellow_range,
green_range,
cyan_range,
blue_range,
magenta_range,
white_range,
black_range
);
// watch value changes
this.pickObj.watch ('x', this.pickedCallback);
this.pickObj.watch ('y', this.pickedCallback);
// handlers
// >> updates pickerMC and position variables
this.pane.onMouseMove = function ()
{
if (this.hitTest (_xmouse, _ymouse, true))
{
// update just when mouse is over the mc
Mouse.hide ();
this.pickerMC._visible = true;
this._parent.pickerPos ();
}
else
{
// mouse is outside the mc
Mouse.show ();
this.pickerMC._visible = false;
}
}
// >> registrates color picking (mouse button down)
this.pane.onMouseDown = function ()
{
if (this.hitTest (_xmouse, _ymouse, true))
{
this._parent.pickObj.downflg = true;
this._parent.pickerPos ();
}
}
// >> registrates color picking (user drags mouse over)
this.pane.onDragOver = function ()
{
if (this.hitTest (_xmouse, _ymouse, true))
{
this._parent.pickObj.downflg = true;
this._parent.pickerPos ();
}
}
// >> release color picking (mouse button up)
this.pane.onMouseUp = function ()
{
if (this.hitTest (_xmouse, _ymouse, true))
{
this._parent.pickObj.downflg = false;
this._parent.pickerPos ();
}
}
// >> releases color picking (user drags mouse out)
this.pane.onDragOut = function ()
{
if (this.hitTest (_xmouse, _ymouse, true))
{
this._parent.pickObj.downflg = false;
this._parent.pickerPos ();
}
}
}
// >> callback function that calls the calcing method that
// >> calcs the color from the actual mouse position
etfColorPickerClass.prototype.pickedCallback = function (id, oldval, newval)
{
if (this.downflg &&
this.x >= 0 && this.y >= 0 &&
this.x <= this.refRoot._width && this.y <= this.refRoot._height
)
{
this.refRoot.setRGB (this.refRoot.calcClass.Calculate (this.x, this.y));
}
return newval;
}
// >> updates picker position and position variables to the actual mouse position
etfColorPickerClass.prototype.pickerPos = function ()
{
this.pickerMC._x = this.pane._xmouse;
this.pickerMC._y = this.pane._ymouse;
this.pickObj.x = this.pane._xmouse;
this.pickObj.y = this.pane._ymouse;
}