Jump to content
Search Community

Array's, Loops and Greensock

Brandesign test
Moderator Tag

Recommended Posts

Hi guys,

 

I've been trying to work this out but just can't get my head around it. The following needs to happen:

 

- 3 Images

- 4 Positions (with 4 values. X, Y, width and height)

- Click on the next button

- Images rotate. 1 goes to position 2, 2 to 3, 3 to 4, and 4 to 1.

 

My solution (that doesn't work) was as followed:

var tlTelefoon = new TimelineMax();

var positions:Array = new Array
				(new Array(267,136,386,520),
				 new Array(236,138,339,456),
				 new Array(204,139,255,343),
				 new Array(420,134,377,540));
				 
var currentPhone:Number = 1;

var phone = new Array("toestel1", "toestel2", "toestel3", "toestel4");

btnNext.onRelease = function(){
	if(currentPhone < 4){
		currentPhone++;
	}
	else{
		currentPhone = 1;
	}
	animatePhone();
}


animatePhone = function(){
	
	for (var i = 0; i < phone.length; i++) {
		tlTelefoon.to(toestel[0], 1, { _x:positions[0].x, _y:positions[0].y, _width:positions[0].width, _height:positions[0].height})
				  .to(toestel[1], 1, { _x:positions[i].x, _y:positions[0].y, _width:positions[0].width, _height:positions[0].height})
				  .to(toestel[2], 1, { _x:positions[i].x, _y:positions[0].y, _width:positions[0].width, _height:positions[0].height})
				  .to(toestel[3], 1, { _x:positions[i].x, _y:positions[0].y, _width:positions[0].width, _height:positions[0].height});
		trace(toestel1);
	}
		
}

In short:

- Button is clicked, var currentPhone increment with 1.

- animatePhone function is called.

- every Phone their values (x,y,w,h) should change an should animate to those spots.

 

Help is very much appriciated! Just can't figure this one out. Maybe I'm just working on it for too long and don't see stupid mistakes. If so, please say so.

 

Thanks!  :-P

 

Youri

 

Link to comment
Share on other sites

Kind of tough to imagine how that code is working and not working.

 

My trouble right now is that positions looks like an array or arrrays... but I don't know what

 

positions[0].x (and similar expressions) are supposed to return.

 

Have you tried tracing out the values you are trying to feed into your tweens? Are you getting the right resluts.

 

 

---

 

also btnNext.onRelease either increments or resets the value  currentPhone and then it calls animatePhone(), but it appears that the value of currentPhone has no bearing on any of the code.

 

---

Link to comment
Share on other sites

Hi Carl,

 

Sorry for my late response. Busy bee. It seems I pasted the old code in, maybe this will clear things up:

var tlTelefoon = new TimelineMax();
var positions:Array = new Array
				(new Array(267,136,386,520),
				 new Array(236,138,339,456),
				 new Array(204,139,255,343),
				 new Array(420,134,377,540));
				 
var currentPhone:Number = 1;
var phone = new Array("toestel1", "toestel2", "toestel3", "toestel4");


/*Button Next */
btnNext.onRelease = function(){
	if(currentPhone < 4){
		currentPhone++;
	}
	else{
		currentPhone = 1;
	}
	animatePhone();
}


animatePhone = function(){
		tlTelefoon	.to(phone[0], 1, { _x:positions[0][0], _y:positions[0][1], _width:positions[0][2], _height:positions[0][3]})
				  	.to(phone[1], 1, { _x:positions[1][0], _y:positions[1][1], _width:positions[1][2], _height:positions[1][3]})
				  	.to(phone[2], 1, { _x:positions[2][0], _y:positions[2][1], _width:positions[2][2], _height:positions[2][3]})
				  	.to(phone[3], 1, { _x:positions[3][0], _y:positions[3][1], _width:positions[3][2], _height:positions[3][3]});
}

It's actually a carousel of some sort. Rotating images on click and with a auto slide after a few seconds.

 

Hope you can help me out!

 

Thanks! 

 

Youri

Link to comment
Share on other sites

Yeah, it seems that code leaves me with less questions, or at least addresses some of my previous concerns. Still, its difficult to imagine what the problem is by just looking at code.

 

Posting the fla (zipped) would help quite a bit. Please understand though that we can't get too deep into figuring out how your project should be constructed. If something obvious pops out, sure, we'd love to help. 

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