Skip to main content
Participant
October 16, 2012
Answered

tie up an object to a mask that is being tweened

  • October 16, 2012
  • 2 replies
  • 753 views

Hi,

I have a mask that is being tweened programatically and then I have an object - a line at the bother of the mask that I want to move together with the mask as if they were tied up together. Is there a way to do it without tweening the line separately as well? I mean to give the line some property so that it knows that it should always copy the motion of the mask.

This is my code:

     myTween1 = new Tween(mask1,"x",null,mask1.x,mask1x,TWEEN_TIME,true);

     new Tween(line1,"x",null,line1.x,line1x,TWEEN_TIME,true);

And I want to get rid of the second line because sometimes it happens that the mask and the line aren't doing the same motion and I can't figure out why. The tween is run after MouseEvent.ROLL_OVER.

Thanks for answer.

Cheers

This topic has been closed for replies.
Correct answer robdillon

You can use the motion change event to control the line. Maybe something like this:

myTween1 = new Tween(mask1,"x",null,mask1.x,mask1x,TWEEN_TIME,true);

myTween1.addEventListener(TweenEvent.MOTION_CHANGE, moveX);

function moveX(event:TweenEvent):void {

          line1.x = mask1.x;

}


2 replies

robdillon
robdillonCorrect answer
Participating Frequently
October 16, 2012

You can use the motion change event to control the line. Maybe something like this:

myTween1 = new Tween(mask1,"x",null,mask1.x,mask1x,TWEEN_TIME,true);

myTween1.addEventListener(TweenEvent.MOTION_CHANGE, moveX);

function moveX(event:TweenEvent):void {

          line1.x = mask1.x;

}


Ned Murphy
Legend
October 16, 2012

You can add them both to a container object (Sprite) and move the Sprite instead of the mask.

var container:Sprite = new Sprite();

container,addChild(mask);

container.addChild(line1);

myTween1 = new Tween(container,"x",null,container.x,container1x,TWEEN_TIME,true);

bavorakAuthor
Participant
October 16, 2012

I've tried it with two normal symbols and it works perfectly but with Symbol that is a Mask and a normal Symbol, I somehow can't make it work but I've already solved the problem the way Rob Dillon suggested it.

Btw: it is also necessary to make: stage.addChild(container) after creating the container and adding children to it.

Anyway thanks. This is a very helpful information for me for future use even though it hasn't solved my problem right now.

Ned Murphy
Legend
October 16, 2012

You're welcome.  Yes, I overlooked adding the container and a typo as well.  I don't see why there would be any difference between using two symbols versus using a symbol/mask since they should still both be objects that you can target with code.  It's good that Rob's solution worked out for you..