Search code examples
actionscript-3flash

Using a variable with currentTarget


Hi I have just posted something simalar but i have not explained it very well. I want a to control the alpha of a movieclip when the mouse is over it . This works fine where 'wedding' is the movie clip .

  wedding.addEventListener(MouseEvent.ROLL_OVER, pan_over) ;



function pan_over(event:MouseEvent):void{
  var ct:String = event.currentTarget.name ; 

  TweenLite.to(wedding, 1, { alpha:0  }); 
 }

What I want to do is use a variable instead of hard coding the word wedding like the example below. But it does not work

wedding.addEventListener(MouseEvent.ROLL_OVER, pan_over) ;
 }


 function pan_over(event:MouseEvent):void{
  var ct:String = event.currentTarget.name ; 

  TweenLite.to(ct, 1, { alpha:0  });
 }

Do I need to declare CT as somwthing other than a string ? . could anyone help please ?

thanks


Solution

  • You can not Tween a String! Stand back and look at your code for a bit. at the moment your example is trying to tween the alpha of the "name" of your Movieclip. What you actually want to do, is tween the alpha property of your Movieclip.

    event.currentTarget is a DisplayObject so you can just use it, even without declaring a variable. Like this...

    function pan_over(event:MouseEvent):void 
    {
        TweenLite.to(event.currentTarget, 1, { alpha:0 }); 
    }
    

    To set the currentTarget to a movieClip variable just do this inside you event handler:

    var cTarget:MovieClip = e.currentTarget as MovieClip;