[Tweener] Using passing variables through event listeners totrigger correct tween
Gerry Creighton
gerry at thespikeranch.com
Wed Dec 10 08:08:33 PST 2008
Yeah you can do it different ways...I just wanted to show you how it's
done in AS3 so that you don't create
'unnecessary code'.
The topic of passing arguments with eventListeners has come up in the
past, Learning Actionscript 3.com
has a post on this very topic that you can read up on here:
http://www.learningactionscript3.com/2008/11/11/passing-arguments-with-events/
The code I passed along allows you to do what you want to do for
rollOvers, rollOuts and the Move but
does not handle the CLICK. The click could be handled easily as well.
-Gerry
On Dec 10, 2008, at 10:59 AM, Graeme Blackwood wrote:
> Thanks Gerry. I'm just interested in looking at different methods.
> I will probably still use a class for the buttons but this is great.
>
> G
>
> From: Gerry Creighton
> Sent: Wednesday, December 10, 2008 3:56 PM
> To: tweener at lists.caurinauebi.com
> Subject: Re: [Tweener] Using passing variables through event
> listeners totrigger correct tween
>
> 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
>
>
>
> _______________________________________________
> Tweener mailing list
> Tweener at lists.caurinauebi.com
> http://lists.caurinauebi.com/listinfo.cgi/tweener-caurinauebi.com
> _______________________________________________
> 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/2ede5195/attachment.htm>
More information about the Tweener
mailing list