PDA

View Full Version : Rollover


SRE
05-21-2010, 07:09 PM
Hi,

what can i do? while i using thousand of rollover function . whether there is any loop function.

generative
05-21-2010, 07:37 PM
maybe this helps

if you put your thousand odjects in array you can do this

for(var i:int=0; i<thousandObjects.lenght; i++)
{
thousandObjects[i].addEventListener(MouseEvent.MOUSE_OVER, overHandler);
}

private function overHandler(event:MouseEvent):void
{
//do some nice animation on event.target object ;)
}

SRE
06-02-2010, 05:08 AM
Hi,
I can't able to label the symbol in array like this
symbol name " objects[1] "
but i know that it is possible
so please help in this

snickelfritz
06-02-2010, 05:42 AM
Use MovieClips for the symbols.
Nest all of the symbols within a MovieClip container.
Give it an instance name: "clips"
Assign a listener and a numeric id property to each symbol within clips.

BTW, you should probably try to get away from using instance names if possible.
They're occasionally helpful, but generally speaking, Strings are a suboptimal way to reference objects in AS3.

import flash.geom.Rectangle;
import flash.events.MouseEvent;
import flash.display.MovieClip;

var targetClip:MovieClip;
var targetID:int;

processChildren(clips.numChildren);

function processChildren(n:int):void
{
var mc:MovieClip;
var rect:Rectangle;

for (var i:int = 0; i < n; i++)
{
mc = MovieClip(clips.getChildAt(i));
mc.id = i;
mc.alpha = .5;
mc.addEventListener(MouseEvent.ROLL_OVER, onOver);
mc.addEventListener(MouseEvent.ROLL_OUT, onOut);
}
}

function onOver(e:MouseEvent):void
{
targetClip = MovieClip(e.currentTarget);
targetID = targetClip.id;

targetClip.scaleX = targetClip.scaleY = 2;
targetClip.alpha = 1;
trace(targetID);
}

function onOut(e:MouseEvent):void
{
targetClip.alpha = .5;
targetClip.scaleX = targetClip.scaleY = 1;
}