Ver Mensaje Individual
  #1 (permalink)  
Antiguo 24/07/2009, 00:41
seresac
 
Fecha de Ingreso: agosto-2006
Mensajes: 81
Antigüedad: 17 años, 8 meses
Puntos: 0
efecto Rasca Rasca

Hola estoy haciendo un rasca rasca como los tipico donde descubres las casillas adeucadas o no. Además cuando calcula que has rascado el 20%, directamente elimina la mascara y descubre la imagen final.

El problema es que funciona pulsando el ratón y necesito que funcione tan solo pasando el ratón por encima.

Ahora mismo nose como hacerlo, dejo aqui el código por si algún buen samaritano puede echarme una manita :(

this.createEmptyMovieClip('mask_mc',0);
bg_mc.setMask(mask_mc);
var contor:Number=0;

var imageHeight:Number = 300; //Image Height
var imageWidth:Number = 250; //Image Width
var totalPixels:Number = imageHeight * imageWidth; //Nombre total de pixels del banner
var almostDonePixelCount:Number = 0.2 * totalPixels; //Percentatge de pixels a eliminar. Actualment 20%
var pixelArray:Array = create2DArray(imageWidth, imageHeight);

// function create2DArray creates a 2D array with x = width and y = height
function create2DArray(width:Number, height:Number):Array
{
var array:Array = Array();
for(var index:Number = 0; index < width; ++index)
array.push(Array(height));
return array;
}


// function drawSquare draws a square on mask_mc MovieClip of sides length 2*r and having center to mouse coordinates.
function drawSquare(mask_mc:MovieClip):Void
{
var r:Number = 30; // mida del puntero mouse
var xcenter:Number = _xmouse; // x co-ordinates of user click
var ycenter:Number = _ymouse; // y co-ordinates of user click

//Draw the square

mask_mc.moveTo(xcenter-r, ycenter-r);
mask_mc.beginFill(0*000000, 100);
mask_mc.lineTo(xcenter-r, ycenter-r);
mask_mc.lineTo(xcenter+r, ycenter-r);
mask_mc.lineTo(xcenter+r, ycenter+r);
mask_mc.lineTo(xcenter-r, ycenter+r);
mask_mc.endFill();

//Loop to set pixels within the square to true

for(var xIndex:Number = xcenter-r; xIndex <= xcenter + r; xIndex++)
{
for(var yIndex:Number = ycenter-r; yIndex <= ycenter + r; yIndex++)
{
pixelArray[xIndex][yIndex] = true;
}
}
}

// function que comproba si l'usuari a rascat el percentatge de pixels necessaris

function scratchDone():Boolean
{
var pixelsScratched:Number = 0;
for(var xIndex:Number = 0; xIndex < imageWidth; xIndex++)
{
for(var yIndex:Number = 0; yIndex < imageHeight; yIndex++)
{
if(pixelArray[xIndex][yIndex] == true)
{
pixelsScratched++;
}
}
}
return pixelsScratched > almostDonePixelCount;
}

// contor variable is used to hold if the mouse is pressed (contor is 1) or not (contor is 0)

this.onMouseDown=function()
{
contor=1;
}

// if the mouse is hold and moved then we draw a square on the mask_mc

this.onMouseMove=this.onEnterFrame=function()
{
if (contor==1)
{

drawSquare(mask_mc);
}
}

// check to see if the upper layer has been scratched

this.onMouseUp=function()
{
contor=0;
if(scratchDone())
{

removeMovieClip(mask_mc);
//trace("rasca rasca terminado");
}

}


Alguien me puede ayudar?