En este tip voy a explicar como usar hitTest en lugar del clasico rollOver y rollOut, ya q con htiTest() obtenemos un código de lectura mas rápida.
Usualmente si quisiéramos hacer un típico botón con fade haríamos lo siguiente:
Código :
btn.onEnterFrame = function (){
this._alpha += (this.transparencia - this._alpha) /6;
}
btn.onRollOver = function (){
this.transparencia = 75;
}
btn.onRollOut = onReleaseOutside = function (){
this.transparencia = 100;
}En este caso no habría mucho problema. Pero, si la animación es mas compleja habría problemas si pasamos el cursor muy rápido, y más si se usa gotoAndPlay()
Ahora con hitTest haríamos lo siguiente:
Código :
btn.onEnterFrame = function (){
this._alpha += (this.transparencia - this._alpha) /6;
//si el cursor esta sobre el boton la transparencia es de 75
if (this.hitTest(_root._xmouse, _root._ymouse, true)) {
this.transparencia = 75;
//si no vuelve a 100
} else{
this.transparencia = 100;
}
}Si quisiéramos darle acciones al clickear usamos onMouseDown
Código :
btn.onMouseDown = function (){
if (this.hitTest(_root._xmouse, _root._ymouse, true)) {
trace("hola mundo");
}
}De esta forma tampoco veríamos la clásica "manito" de los botones, pero no tenemos mas que habilitarla cuando el cursor esta sobre el botón
Código :
useHandCursor = true;

Por HernanRivas el 10 de Julio de 2007
Por Ricardo Zacarias el 17 de Noviembre de 2008
function chechPos (){
for (a in hitCiudad){if(hitCiudad[a].hitTest(_xmouse,_ymouse,1)){
cambiarColor(textCiudad[a],100,0xff0000);
}else{
cambiarColor(textCiudad[a],100,0x660000);
};//if
};//for;
};//function chechPos
dicha funcion la llamao desde un evento
textCiudad[0].onMouseMove = function (){
chechPos ();
updateAfterEvent();
};//mouseMove