[Tweener] Using passing variables through event listeners to trigger correct tween

Graeme Blackwood grayhammy at hotmail.com
Wed Dec 10 04:16:59 PST 2008


Hi,

I have a navigation menu of 12 buttons, and I want to treat them all in the same way, so it seems silly to write out the same code for every single button.  I am trying to create an array that holds the button instances, and then run through a loop to set up the Event Listeners, passing through which item in the array should be triggered and tweening that item appropriately.  For some reason

Somehow the value of variable "i" is not getting through to my functions.  Is this a good way to do this, so as not to create unnecessary code?

Many thanks,

Graeme

import caurina.transitions.Tweener;

var navigationArray:Array = new Array();

navigationArray[0] = newsButton;
navigationArray[1] = musicButton;

for(var i:uint = 0; i<navigationArray.length; i++) {
    navigationArray[i].addEventListener(MouseEvent.ROLL_OVER, function(e:MouseEvent):void {navButtonRollOver(e,i);});
    navigationArray[i].addEventListener(MouseEvent.MOUSE_MOVE, function(e:MouseEvent):void {navButtonMove(e,i);});
    navigationArray[i].addEventListener(MouseEvent.ROLL_OUT, function(e:MouseEvent):void {navButtonRollOut(e,i);});
}

 function navButtonRollOver(e:MouseEvent,arrayItem):void {
     Tweener.addTween(navigationArray[arrayItem], {alpha:1, time:1, transition:"easeOut"});
 }
 
 function navButtonMove(e:MouseEvent,arrayItem):void {
     navigationArray[arrayItem].gotoAndStop(navigationArray[arrayItem].mouseX);
 }
 
 function navButtonRollOut(e:MouseEvent,arrayItem):void {
     Tweener.addTween(navigationArray[arrayItem], {alpha:0, time:2, transition:"easeOut"});
 }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.caurinauebi.com/pipermail/tweener-caurinauebi.com/attachments/20081210/d5735585/attachment.htm>


More information about the Tweener mailing list