Jump to content
Search Community

Using a string for the tween object [SOLVED]

barryg test
Moderator Tag

Recommended Posts

You cannot tween a String - your code is literally trying to tween the word "myObject"'s alpha property :) I assume you're trying to tween the object that is named "myObject". Assuming your code is on a MovieClip, you could do something like:

 

tweenObject:String = "myObject";
TweenLite.to(this[tweenObject], 0.25, {alpha:0.7, ease:Quad.easeOut});

Link to comment
Share on other sites

A mouse event handler is being called within a AS3 Class. A switch is performed on the target.name to determine the sprite that needs to be tween which is what I called the "tweenObject".

All my code takes place within a class. I have one method that is being called from the time-line where one or more jpg's are passed in as arguments.

My code works if the TweenLite.to(..) is added to each case within the switch.

I do not believe that "this" can be used.

Link to comment
Share on other sites

Here's the method that I'm using

private function overThumbHandler(evt:MouseEvent):void
	{	
		switch (evt.target.name)
		{
			case "Thumb_1": TweenLite.to(loader1, 0.25, {alpha:1.0, ease:Quad.easeOut});	break;				
			case "Thumb_2": TweenLite.to(loader2, 0.25, {alpha:1.0, ease:Quad.easeOut});	break;
			case "Thumb_3": TweenLite.to(loader3, 0.25, {alpha:1.0, ease:Quad.easeOut});	break;
		}
	}

I would like to have the switch determine the target as a string within the switch logic and then have one tween below the switch.

Link to comment
Share on other sites

Lots of ways you could handle this. What about using an Object as a lookup of sorts, like:

 

var loaders:Object = {Thumb_1:loader1, Thumb_2:loader2, Thumb_3:loader3};
private function overThumbHandler(evt:MouseEvent):void {   
     TweenLite.to(loaders[evt.target.name], 0.25, {alpha:1.0, ease:Quad.easeOut});           
}

Link to comment
Share on other sites

Using a switch, A new object is created and being assign to the object that I want to tween, base upon evt:target.name. This new instance object is then being used as the target in the tween.

This fixed the problem that I was having trying to use the String directly in the tween.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...