Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tweening with Sliders

Status
Not open for further replies.

capeachino

Technical User
Oct 29, 2007
1
CA
Hi everyone,

You can download the file from here:

so I have this very simple slider which when you drag it, it switches between 5 MCs. What I want to do is when the slider is at the point where it should switch the MCs a simple fade tweening happens.

I have been going crazy trying to figure it out. Please any help is very much appreciated. I am sure it's an easy fix, but I really can't figure it out.

Thanks a Million!!



Here's the CODE that's on the frame 1 in the stage:


stop();

// What's Visible

import mx.transitions.*;
import mx.transitions.easing.*;


mc01._alpha = 100;
mc02._alpha = 0;
mc03._alpha = 0;
mc04._alpha = 0;
mc05._alpha = 0;


// Slider MC interaction
this.onEnterFrame=function(){

if (sliding.ratio >= 0)
{

new Tween(mc01, "_alpha", Regular.easeOut, 0, 100, 1, true);
mc02._alpha = 0;
mc03._alpha = 0;
mc04._alpha = 0;
mc05._alpha = 0;


if (sliding.ratio >= 20)
{

new Tween(mc01, "_alpha", Regular.easeOut, 100, 0, 1, true);
new Tween(mc02, "_alpha", Regular.easeOut, 0, 100, 1, true);
mc03._alpha = 0;
mc04._alpha = 0;
mc05._alpha = 0;

if (sliding.ratio >= 40)
{
mc01._alpha = 0;
new Tween(mc02, "_alpha", Regular.easeOut, 100, 0, 1, true);
new Tween(mc03, "_alpha", Regular.easeOut, 0, 100, 1, true);
mc04._alpha = 0;
mc05._alpha = 0;


if (sliding.ratio >= 60)
{
mc01._alpha = 0;
mc02._alpha = 0;
new Tween(mc03, "_alpha", Regular.easeOut, 100, 0, 1, true);
new Tween(mc04, "_alpha", Regular.easeOut, 0, 100, 1, true);
mc05._alpha = 0;

if (sliding.ratio >= 80)
{
mc01._alpha = 0;
mc02._alpha = 0;
mc03._alpha = 0;
new Tween(mc04, "_alpha", Regular.easeOut, 100, 0, 1, true);
new Tween(mc05, "_alpha", Regular.easeOut, 0, 100, 1, true);
}
}
}
}
}
}
 
Code:
import mx.transitions.*;
import mx.transitions.easing.*;

stop();

// Slider MC interaction
this.onEnterFrame = function() {
	if (sliding.ratio<20) {
		fade(mc01);
	} else if (sliding.ratio<40) {
		fade(mc02);
	} else if (sliding.ratio<60) {
		fade(mc03);
	} else if (sliding.ratio<80) {
		fade(mc04);
	} else {
		fade(mc05);
	}
};

function fade(targetMC:MovieClip) {
	if (!targetMC.init) {
		targetMC.init = true;
		targetMC.twn.stop();
		targetMC.twn = new Tween(targetMC, "_alpha", Regular.easeOut, targetMC._alpha, 100, 1, true);

		for (var i = 1; i<=5; i++) {
			var mc = this["mc0"+i];
			if (mc != targetMC) {
				mc.init = false;
				mc.twn.stop();
				mc.twn = new Tween(mc, "_alpha", Regular.easeOut, mc._alpha, 0, 1, true);
			}
		}
	}
}

Kenneth Kawamoto
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top