Jump to content
Search Community

Using if and else to tween the alpha and position?!

Procise test
Moderator Tag

Recommended Posts

Any info on how this could be done? I used mc.visible == False and it worked but Im looking for a smooth alpha change and I dont know how to set that up. help please. also I can get the position of the mc to move on screen and off but wont move back on screen!

Link to comment
Share on other sites

I don't understand the question.

 

what exactly is supposed to happen? what code are you currently using?

 

more specifically what condition is going to determine that the alpha and position should change?

 

the more specific you can be the better, such as:

 

how do I test if the x of my mc is greater than 500 and then make it fade out?

 

 

thanks

Link to comment
Share on other sites

I would like to learn how to toggle the alpha with if and else but not just to have it switch on and off like a light but over a period of time, dunno like .8 secs and also the y position ..I attached what I have so far if ya test the fla you will see some issues with if not more lol...like when you click on the black box everything is effected and thats probably because I am using event.target.parent..I dont want anything to happen if you were to click on the black box just the grey circle or the smaller red box. Hope I was clear appreciate it.

Link to comment
Share on other sites

your new description and file made things slightly more clear. thanks.

 

Assuming you want the red button to make the black box go down and fade out and then toggle that animation on subsequent clicks, you really don't need an if else. You can simply reverse the direction of a tween every time the red button is clicked so each click would play forward - reversed - forward - reversed etc...

 

here is the shortest way:

 

var tween:TweenLite = TweenLite.to(mc, .8, {y:400, alpha:0, paused:true, reversed:true});

toggle_btn.addEventListener(MouseEvent.CLICK, toggleTween);

function toggleTween(e:MouseEvent):void{

tween.reversed = !tween.reversed;
tween.resume();

}

 

if you want to use an if, you can use more code, maybe its easier to understand.

 

var isOpen:Boolean = true;

var tween:TweenLite = TweenLite.to(mc,.8,{y:400,alpha:0,paused:true});

toggle_btn.addEventListener(MouseEvent.CLICK, toggleTween);

function toggleTween(e:MouseEvent):void {

if (isOpen) {
	tween.play();
}
else {
	tween.reverse();
}
isOpen = !isOpen;
}

 

cs4 fla's for both attached.

 

to see how to use the same tween reverse toggle technique in a more elaborate animation check out:

http://www.snorkl.tv/2011/08/peacock-ch ... melinemax/

Link to comment
Share on other sites

I saw your video very helpful but I wanted to learn how to use if and else conditionals and I figured it out using "if" and "else if" after hours of messing around...but I do like how you used a variable to put all the information in it with my practice file..But what happens if I wanted to have the alpha take .5 secs would I have to make another variable for the alpha?

 

 

like this?

 

var isOpen:Boolean = true;

 

var tweenpos:TweenLite = TweenLite.to(mc,.8,{y:400,alpha:0,paused:true});

var tweenalpha:TweenLite = TweenLite.to(mc,.5{alpha:0});

toggle_btn.addEventListener(MouseEvent.CLICK, toggleTween);

 

function toggleTween(e:MouseEvent):void {

 

if (isOpen) {

tweenpos.play();

tweenalpha.play(); }

else {

tweenpos.reverse();

tweenalpha.reverse(); }

isOpen = !isOpen;

}

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