Jump to content
Search Community

TweenMax code

ajmeraviglia test
Moderator Tag

Recommended Posts

Hi,

In the example (Ejemplo.fla) I send I have made a number of movieclips that go from alpha:100 to alpha:20 when you click the adequate button.

 

One movieclip changes its alpha to 20 while the rest goes to alpha:100.

 

Is there a way to avoid writing all the alpha that don’t change for each button?

 

Instead of:

Btn01.onRelease = function():Void {
var twMove:TweenMax = new
TweenMax.to(MC1,0.1,{_alpha:20});
TweenMax.to(MC2,0.1,{_alpha:100});
TweenMax.to(MC3,0.1,{_alpha:100});

…and so on for each MC
}

 

And so for each button,

 

Say, for example, MC1 go to alpha 20; all the rest of MCs go to alpha:100? With conditionals, for example?

 

Thank you.

 

Alejandro

Link to comment
Share on other sites

from your ejemplo it seems only the previously selected clip needs to come back up to 100, as opposed to "every other movie clip".

 

replace your code with the following:

 

import com.greensock.*;
import com.greensock.easing.*;
//Comienzo//

//Mc
TweenMax.to(MC1,0.1,{_alpha:100});
TweenMax.to(MC2,0.1,{_alpha:100});
TweenMax.to(MC3,0.1,{_alpha:100});


// keep track of recently selected / active mc

var currentMC:MovieClip;

Btn01.onRelease = function():Void  {

setActive(MC1);
};

Btn02.onRelease = function():Void  {
setActive(MC2);

};

Btn03.onRelease = function():Void  {

setActive(MC3);
};

function setActive(mc) {

//if there is a currently active mc, tween it up
if (currentMC) {
	TweenMax.to(currentMC,.5,{_alpha:100});
}


//set currentMC to newly selected mc 
currentMC = mc;

//tween down current mc
TweenMax.to(currentMC,.5,{_alpha:20});
}

 

if you really wanted every other movie clip to do something when a new movie clip is selected you could use a for loop like this:

 

http://www.snorkl.tv/2011/01/fade-hide- ... ling-over/

Link to comment
Share on other sites

This works well when a button acts on one propperty of one MC.

I did'nt think about it when I made the Ejemplo, but what if the same button must change two different propperties in two different MC?

 

In Ejemplo02 I want Btn01 to change MC01's alpha and MC04 position all at the same time.

 

Is there a way to make three, four... properties, each one in a different MC and with one button, using a similar code? That's what I need to do.

 

Thank you for your help.

 

Alejandro

Link to comment
Share on other sites

I'm glad the first problem was solved.

 

this new ejemplo opens a lot of questions:

 

does only Btn01 change the position of MC04, what about the other buttons?

what position is MC04 changing too?

 

what buttons set MC04 position back to normal?

 

does pressing Btn02 move other clips to other positions?

 

there are way too many variables and unknowns here to build a flexible system for you. and I regret, even if you did provide all the information, we can't be building projects for you. we have to stay focused on helping people with understanding the internal workings of the GreenSock tweening platform.

 

i'm sure anything you can imagine is possible, but it may require a fairly complex approach beyond what you understand of ActionScript at this time. if all the mc's are going to the same place, you can certainly add new tweens right where the alpha tweens are set in the existing code. if MC04, goes somewhere different than MC02... its not easy. you can start by giving each mc its own destination values like

 

mc01.destinationX = 200;

mc01.destiniationY = 300;

 

and then your tween's could reference those unique values for each mc that gets moved. again, it isn't necessarily painless.

Link to comment
Share on other sites

Ok. I will work on it for a while. I understand what you say about building systems for me. In fact, I know the main problem resides in a poor level of AS.

If I ever get to a solution I will share it here in case it is useful for anybody. Or if a have a more concrete doubt maybe I ask again.

 

Thank you again for your time, anyway. I can use the first solution while I try something for the other problem.

 

Alejandro

Link to comment
Share on other sites

  • 1 month later...

Hi.

I dont' know if this can be useful for someone, but I started to find solutions for the problems I had in October and I want to post them in case It can be helpful.

 

Using loops and arrays is simplifying a lot the code I am using. Instead of writng the same code over and over for each button I am doing this:

 

import com.greensock.*;
import com.greensock.easing.*;


//Initial status of Buttons and Mc's

TweenMax.to(MC1,0.1,{_alpha:100});
TweenMax.to(BT1, 0.1, {_alpha:0});
TweenMax.to(MCBolo1,0.1,{_alpha:100});
TweenMax.to(MCVara1,0.1,{_alpha:100});

BT1.enabled = false;


//Estado de los botones de interface. Buttons status
for (i = 0; i < 9; i++) {

this["BT" + i].onRelease = function(){
selec = Number(this._name.slice(2));	

alfear();
};
}


function alfear() {
for (i = 0; i < 9; i++) {
	TweenMax.to(this["MC"+i],0.3,{_alpha:0});
	TweenMax.to(this["MCBolo"+i],0.3,{_alpha:0});
	TweenMax.to(this["MCVara"+i],0.3,{_alpha:0});
	TweenMax.to(this["BT" + i],0.3,{_alpha:100});
	this["BT" + i].enabled = true;
}

this["BT" + selec].enabled = false;
TweenMax.to(this["MC" + selec],0.3,{_alpha:100});
TweenMax.to(this["MCBolo"+selec],0.3,{_alpha:100});
TweenMax.to(this["MCVara"+selec],0.3,{_alpha:100});
TweenMax.to(this["BT"+selec],0.3,{_alpha:0});
}

//Changing the size of circles and bars

A_escalar=new Array(0,125,121,113,110,92,106,95,93);

for (i = 0; i < 9; i++) {

	TweenMax.to(this["MCBolo"+i],0.3,{_xscale:A_escalar[i], _yscale:A_escalar[i],ease:Quart.easeOut});
}

A_alargar=new Array(0,231,139,139,0,277,332,63,554);

for (i = 0; i < 9; i++) {

	TweenMax.to(this["MCVara"+i],0.3,{_xscale:A_alargar[i],ease:Quart.easeOut});
}

 

This is not perfect, as can be seen in the .fla: I haven't been able to make it work for just one MCBolo and one MCVara, so I have to bear those ugly alpha transitions between MCBolo1 and 2 and so on, and between MCVara1 and 2 and so on.

And I haven't been able to use different values for duration. Even using different functions for the different tweenings it will always use the first it reads.

 

But it is better than it was just a month ago and I am working on it.

 

Hope it can help somebody. Thank you for your work,

 

Alejandro.

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