Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
Luigi Vercotti

Tweening each one seperately

Recommended Posts

Hello ;-)

Can you please help me to tween each of the _num seperately (of the array), because it tweens all of them at the same time when I roll over them.

;-)



import com.greensock.*;
import com.greensock.easing.*;
import flash.events.MouseEvent;


var cell: phone = new phone;
var _plus: plus = new plus;
var _numZeroOne: numZero = new numZero;
var _numZeroTwo: numZero = new numZero;
var _numZeroThree: numZero = new numZero;
var _numFour: numFour = new numFour;
var _numTwo: numTwo = new numTwo;
var _numThree: numThree = new numThree;
var _numSevenOne: numSeven = new numSeven;
var _numSevenTwo: numSeven = new numSeven;
var _numSevenThree: numSeven = new numSeven;
var _numSevenFour: numSeven = new numSeven;
var _numNine: numNine = new numNine;
var _numFive: numFive = new numFive;

cell.x = 100;
cell.y = 100;
//addChild (cell);


var arrayCellNum: Array = new Array(_plus, _numFour, _numTwo, _numZeroOne, _numSevenOne, _numSevenTwo, _numFive, _numZeroTwo, _numSevenThree, _numSevenFour, _numNine, _numThree, _numZeroThree);
for (var cl: int = 0; cl < arrayCellNum.length; cl++) {
	arrayCellNum[cl].addEventListener(MouseEvent.ROLL_OVER, phoneOver);
	arrayCellNum[cl].buttonMode = true;
	arrayCellNum[cl].x = 18 * cl;

	addChild(arrayCellNum[cl]);

}

function phoneOver(e: MouseEvent): void {
	for (var tw: int = 0; tw < arrayCellNum.length; tw++) {
		var high = 4;
		var low = 1;
		var randint: Number = Math.floor(Math.random() * (1 + high - low)) + low;
		var highX = 40;
		var lowX = 0;
		var randintX: Number = Math.floor(Math.random() * (1 + highX - lowX)) + lowX;


		var myTween: TimelineLite = new TimelineLite();
		myTween.append(new TweenMax(arrayCellNum[tw], .1, {
			rotationX: randintX,
			rotationZ: randint
		}));
		myTween.append(new TweenMax(arrayCellNum[tw], .1, {
			rotationX: -(randintX),
			rotationZ: -2
		}));
		myTween.append(new TweenMax(arrayCellNum[tw], .1, {
			rotationX: 0,
			rotationZ: 0
		}));
	}
}
Link to comment
Share on other sites

hmm, it appears that each time you mouse over each element you are running a loop through all the items in the Array and creating animations for each item.

 

I think you need to simply find the target of the ROLL_OVER event and animate that instead. Sort of like

 

function phoneOver(e: MouseEvent): void {

var high = 4;
var low = 1;
var randint: Number = Math.floor(Math.random() * (1 + high - low)) + low;
var highX = 40;
var lowX = 0;
var randintX: Number = Math.floor(Math.random() * (1 + highX - lowX)) + lowX;


trace("you rolled over " + e.target)

var myTween: TimelineLite = new TimelineLite();
 myTween.to(e.target, 1, {rotation:360})

}

If tough to diagnose such an issue from just seeing the code you pasted as there is nothing we can do to test it.

Feel free to supply a simplified fla.

 

Also, please read this tutorial and the resource it links to as it may help you better understand how to figure out which item you are rolling over and write less code: http://www.snorkl.tv/2010/08/assign-eventlisteners-to-multiple-movie-clips-in-a-single-blow-a-look-at-target-vs-currenttarget/

  • Like 1
Link to comment
Share on other sites

That article "Assign EventListeners to Multiple Movie Clips in a Single Blow! A look at target vs currentTarget" is so cool :-)

I am using tons of code and this could help me with the problem I am having and with my huge amount of codes....Thank you very much.

 

I tried to upload the file but it says incorrect file :-(

 

Thank you again and I will in to it. 

 

;-)

 

Later after more learning :-) and testing and it is working the way I wished. Thank you very much :-))))



var cell: phone = new phone;
addChild(cell);
cell.x = 100;
cell.y = 100;

//add hand cursor
cell.buttonMode = true;
cell.useHandCursor = true;

//assign eventListeners
cell.addEventListener(MouseEvent.MOUSE_OVER, cellOver);

function cellOver(e: MouseEvent): void {

	var high = 4;
	var low = 1;
	var randint: Number = Math.floor(Math.random() * (1 + high - low)) + low;
	var highX = 40;
	var lowX = 0;
	var randintX: Number = Math.floor(Math.random() * (1 + highX - lowX)) + lowX;
	var randintY: Number = Math.floor(Math.random() * (1 + highX - lowX)) + lowX;

	var myTween: TimelineLite = new TimelineLite();
	myTween.append(new TweenMax(e.target, .1, {
		rotationX: randintX,
		rotationX: -(randintX),
		rotationZ: randint,
		rotationY: randintY,

		rotationY: -(randintX),
		ease: Elastic.easeOut
	}));
	myTween.append(new TweenMax(e.target, .1, {
		rotationX: -(randintX),
		rotationZ: -2,
		rotationY: -(randintX),
		ease: Elastic.easeOut
	}));
	myTween.append(new TweenMax(e.target, .1, {
		rotationX: 0,
		rotationZ: 0,
		rotationY: 0
	}));
}

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.
×