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

Gerry Creighton gerry at thespikeranch.com
Wed Dec 10 07:56:28 PST 2008


Graeme,
Your code should look more like this...
I made an fla with two movieClips sitting on the stage with one above  
the other (y:50 + y:100) with instance
names "news" and "music".

Hope that helps.

-Gerry


<code>
import caurina.transitions.Tweener;

var navigationArray:Array = new Array();

navigationArray[0] = news;
navigationArray[1] = music;

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

  function navButtonRollOver(e:MouseEvent):void {
      Tweener.addTween(e.target, {alpha:1, time:1,  
transition:"easeOut"});
  }

  function navButtonMove(e:MouseEvent):void {
     // this.gotoAndStop(e.target.mouseX);
	  Tweener.addTween(e.target, {x:e.target.mouseX+(e.target.width/2),  
time:2, transition:"easeOut"});
  }

  function navButtonRollOut(e:MouseEvent):void {
      Tweener.addTween(e.target, {alpha:.5, time:2,  
transition:"easeOut"});
  }
</code>


On Dec 10, 2008, at 7:16 AM, Graeme Blackwood 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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.caurinauebi.com/pipermail/tweener-caurinauebi.com/attachments/20081210/cb56971c/attachment.htm>


More information about the Tweener mailing list