Hi all!
I am currently starting to learn AS3 and I stumbled on a problem which I can not solve myself. I searched for sollutions on the internet but nothing seems to be the solution I am looking for.
I am calling a movieclip from the library to stage stage multiple times. Then when its on the stage I want to add an roll_over and a roll_out effect to ALL the movieclips. I know that the problem of my code is in the part where I link the eventlistener to the movieclip because the name is not right. It only works on the last placed movieclip.
So can anybody tell me how to make it work for all movieclips?
here is my code:
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;
function placeElements(aantal:int, kolommen:int, marge:int):void
{
var teller:Number = 0;
var locX:Number = marge;// start x positie
var locY:Number = marge;// start y positie
for (var i=0; i<aantal; i++)
{
var placeMC : MovieClip = new holder();// same class name taken from symbol
placeMC.x = locX; // x locatie
placeMC.y = locY; // y locatie
placeMC.alpha = (100/10)/100; // tranparantie
placeMC.name = "holder" + *;// naam geven
placeMC.link = "http://www.url"+*+".nl"; // url meegeven
addChild( placeMC );// toevoegen aan stage
locX += (placeMC.width + marge);// nieuwe x locatie maken
teller++;// teller omhoog
//placeMC.addEventListener(MouseEvent.ROLL_OVER, restoreAlpha);
placeMC.addEventListener(MouseEvent.ROLL_OVER, restoreAlpha);
function restoreAlpha(event:MouseEvent):void
{
removeEventListener(MouseEvent.ROLL_OVER, restoreAlpha);
addEventListener(MouseEvent.ROLL_OUT, lowerAlpha);
//var raT:Tween = new Tween(object, "property", EasingType, begin, end, duration, useSeconds);
var myTween:Tween = new Tween(placeMC, "alpha", Strong.easeOut, 0.1, 1, 2, true);
}
placeMC.addEventListener(MouseEvent.ROLL_OUT, lowerAlpha);
function lowerAlpha(event:MouseEvent):void
{
removeEventListener(MouseEvent.ROLL_OUT, lowerAlpha);
addEventListener(MouseEvent.ROLL_OVER, restoreAlpha);
var myTween:Tween = new Tween(placeMC, "alpha", Strong.easeOut, 1, 0.1, 2, true);
}
if (teller == kolommen)
{
locY += (placeMC.height + marge);// nieuwe y locatie maken
locX = marge;
teller = 0;
}
}
}
placeElements(12, 4, 20);