[Tweener] Using passing variables through event listeners to trigger correct tween
Baluta Cristian
cristi.baluta at gmail.com
Wed Dec 10 04:28:38 PST 2008
i'm not shure you can send arguments like that, and the code is ugly also.
two solutions:
1. i hope your buttons are classes. add events inside the class, the button
2. use custom events but is much more complicated because you have to pass
the "i" to the class, then dispatch the events with that "i". and you also
need to add the custom event from outside the button.
On Wed, Dec 10, 2008 at 2:16 PM, Graeme Blackwood <grayhammy at hotmail.com>wrote:
> 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"});
> }
>
> _______________________________________________
> Tweener mailing list
> Tweener at lists.caurinauebi.com
> http://lists.caurinauebi.com/listinfo.cgi/tweener-caurinauebi.com
>
>
--
Baluta Cristian
http://ralcr.com
http://imagin.ro
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.caurinauebi.com/pipermail/tweener-caurinauebi.com/attachments/20081210/f013cccb/attachment.htm>
More information about the Tweener
mailing list