PDA

View Full Version : how to tween with currentTarget?


Prionkor
02-04-2010, 10:28 AM
Hi,

Let i have 5 instants of a class say class_1 in the stage which i add by for loop. here is the code:

xPositions:Array = new Array(75, 175, 275, 75, 175, 275, 75, 175, 275);
var yPositions:Array = new Array(75, 75, 75, 175, 175, 175, 275, 275, 275);

for(var i:uint = 0; i < 8; i++){
var thisOne:GameButton = new GameButton();
addChild(thisOne);
thisOne.x = xPositions[i];
thisOne.y = yPositions[i];
}

now it want to select an object and then when i click in the any point in the stage i want to the selected object to tween there.

I know how to use Tween class. But problem is how do i get the name of the instant

here is the code for tween i used. The name of the selected object will be in the 'name of the object'. I can not retrieve the name of the clicked object.

new Tween(name of the object, "x", None.easeIn, xPosition, mouseX, 1, true);
new Tween(name of the object, "y", None.easeIn, yPosition, mouseY, 1, true);

please help!

shan.swf
02-05-2010, 06:32 AM
import tween class on stage.

dhil dhil senthil
02-05-2010, 09:15 AM
////////////////////////////////////////////////////////////////////
import com.greensock.TweenLite;
import com.greensock.easing.*;
////////////////////////////////////////////////////////////////////
var xPositions:Array=new Array(75,175,275,75,175,275,75,175,275);
var yPositions:Array=new Array(75,75,75,175,175,175,275,275,275);
////////////////////////////////////////////////////////////////////
var currentButton:GameButton;
for (var i:uint = 0; i < 8; i++) {
var thisOne:GameButton = new GameButton();
addChild(thisOne);
thisOne.x=xPositions[i];
thisOne.y=yPositions[i];
thisOne.addEventListener(MouseEvent.CLICK,onButton Click);
}
////////////////////////////////////////////////////////////////////
stage.addEventListener(MouseEvent.MOUSE_UP,chaseMo use);
////////////////////////////////////////////////////////////////////
function onButtonClick(e:MouseEvent) {
if (currentButton) {
currentButton.gotoAndStop(1);
}
currentButton=GameButton(e.currentTarget);
currentButton.gotoAndStop(2);
}
////////////////////////////////////////////////////////////////////
function chaseMouse(e:MouseEvent) {
if (!this.hitTestPoint(stage.mouseX,stage.mouseY,true )) {
if (currentButton) {
TweenLite.to(currentButton,1,{x:currentButton.pare nt.mouseX,y:currentButton.parent.mouseY});
}
}
}
////////////////////////////////////////////////////////////////////;)
Better to use TweenLite Family than the adobe default tween. I Love it.Please download the attachment.Hope it helps.

Prionkor
02-05-2010, 06:51 PM
Looks great! Thank you for your help.