Ultrashock Forums > Flash > ActionScript
AS2 - refine my code...it sucks : Six clips fade. Rollover one...other Fade out

You are currently viewing our website as a guest which gives you limited access to forums, files and other resources.

Click here to join now for free, and start interacting with our members, download files and much more!

Click here if you are looking for our Flash files and other professional assets.
 
Post Reply | View first unread | Rate Thread Search this Thread | Thread Tools | Display Modes

#1
Bookmark and Share!
AS2 - refine my code...it sucks : Six clips fade. Rollover one...other Fade out
Old 2008-05-05

So I have six movie clips. When you rollover one I want the other five to fade out. this code that I did works but it has a potential to break with quick strokes. Any help would be great thanks. I also have a button surrounding the six clips that fade all back up. The reason for that is while they are going from clip to clip i dont want them to fade in a out.

------Here is a link of what im trying to acheiving.------
http://www.stellamccartney.com/us/en/beauty/

Thanks alot everyone.

------And here is my code-------

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

function fadeOut(mc) {
var begin = 100;
var end = 25;
var time = .1;
var myTween:Tween = new Tween(mc, "_alpha", Regular.easeOut, begin , end , time , true);
}

function fadeIn(mc) {
var begin = 25;
var end = 100;
var time = .1;
var myTween:Tween = new Tween(mc, "_alpha", Regular.easeIn, begin , end , time , true);
}

btnOff.onRollOver = function() {
if (by1._alpha != "100") {
fadeIn(by1);
}
if (by2._alpha != "100") {
fadeIn(by2);
}
if (by3._alpha != "100") {
fadeIn(by3);
}
if (by4._alpha != "100") {
fadeIn(by4);
}
if (by5._alpha != "100") {
fadeIn(by5);
}
if (by6._alpha != "100") {
fadeIn(by6);
}
};

by1.onRollOver = function() {
if (by1._alpha != "100") {
fadeIn(by1);
}
if (by2._alpha != "25") {
fadeOut(by2);
}
if (by3._alpha != "25") {
fadeOut(by3);
}
if (by4._alpha != "25") {
fadeOut(by4);
}
if (by5._alpha != "25") {
fadeOut(by5);
}
if (by6._alpha != "25") {
fadeOut(by6);
}
};

by2.onRollOver = function() {
if (by2._alpha != "100") {
fadeIn(by2);
}
if (by1._alpha != "25") {
fadeOut(by1);
}
if (by3._alpha != "25") {
fadeOut(by3);
}
if (by4._alpha != "25") {
fadeOut(by4);
}
if (by5._alpha != "25") {
fadeOut(by5);
}
if (by6._alpha != "25") {
fadeOut(by6);
}
};

by3.onRollOver = function() {
if (by3._alpha != "100") {
fadeIn(by3);
}
if (by1._alpha != "25") {
fadeOut(by1);
}
if (by2._alpha != "25") {
fadeOut(by2);
}
if (by4._alpha != "25") {
fadeOut(by4);
}
if (by5._alpha != "25") {
fadeOut(by5);
}
if (by6._alpha != "25") {
fadeOut(by6);
}
};

by4.onRollOver = function() {
if (by4._alpha != "100") {
fadeIn(by4);
}
if (by1._alpha != "25") {
fadeOut(by1);
}
if (by2._alpha != "25") {
fadeOut(by2);
}
if (by3._alpha != "25") {
fadeOut(by3);
}
if (by5._alpha != "25") {
fadeOut(by5);
}
if (by6._alpha != "25") {
fadeOut(by6);
}
};

by5.onRollOver = function() {
if (by5._alpha != "100") {
fadeIn(by5);
}
if (by1._alpha != "25") {
fadeOut(by1);
}
if (by2._alpha != "25") {
fadeOut(by2);
}
if (by3._alpha != "25") {
fadeOut(by3);
}
if (by4._alpha != "25") {
fadeOut(by4);
}
if (by6._alpha != "25") {
fadeOut(by6);
}
};

by6.onRollOver = function() {
if (by6._alpha != "100") {
fadeIn(by6);
}
if (by1._alpha != "25") {
fadeOut(by1);
}
if (by2._alpha != "25") {
fadeOut(by2);
}
if (by3._alpha != "25") {
fadeOut(by3);
}
if (by4._alpha != "25") {
fadeOut(by4);
}
if (by5._alpha != "25") {
fadeOut(by5);
}
};
postbit arrow 7 comments | 875 views postbit arrow Reply: with Quote   
Registered User
bigpandesal is offline
seperator
Posts: 5
2008-05-05
bigpandesal lives in United States
seperator

Ultrashock Member Comments:
Isocase's Avatar Isocase Isocase is offline Isocase lives in United States 2008-05-06 #2 Old  
Here is some quick code that you can take a look at. You just need to loop through your mc's.

ActionScript Code:
  1. import mx.transitions.Tween;
  2. import mx.transitions.easing.*;
  3.  
  4. var container:MovieClip = createEmptyMovieClip( "container", 0 );
  5. var offsetX:Number = 0;
  6.  
  7. var i:Number = -1;
  8. var n:Number = 8;
  9.  
  10. while( ++ i < n )
  11. {
  12.     var mc:MovieClip = container.attachMovie( "Box", "box_" + i, i );
  13.     mc._x = offsetX;
  14.    
  15.     setupButtons( mc );
  16.    
  17.     offsetX += mc._width;
  18. }
  19.  
  20. container._x = ( Stage.width - container._width ) >> 1;
  21. container._y = ( Stage.height - container._height ) >> 1;
  22.  
  23. function setupButtons( button:MovieClip ):Void
  24. {
  25.     button.onRollOver = rollOverHandler;
  26.     button.onRollOut = rollOutHandler;
  27. }
  28.  
  29. function rollOverHandler():Void
  30. {
  31.     var i:Number = 8;
  32.    
  33.     while( i -- )
  34.     {
  35.         if( container[ "box_" + i] != this )
  36.         {
  37.             new Tween( container[ "box_" + i], "_alpha", Strong.easeOut, 100, 50, .1, true );
  38.         }
  39.     }
  40. }
  41.  
  42. function rollOutHandler():Void
  43. {
  44.     var i:Number = 8;
  45.    
  46.     while( i -- )
  47.     {
  48.         new Tween( container[ "box_" + i], "_alpha", Strong.easeOut, 50, 100, .1, true );
  49.     }
  50. }
Reply With Quote  
bigpandesal bigpandesal is offline bigpandesal lives in United States 2008-05-06 #3 Old  
Thanks so much
Ill give it a try
Reply With Quote  
bigpandesal bigpandesal is offline bigpandesal lives in United States 2008-05-06 #4 Old  
Sorry to be a noob....Do I just name my movie clip instances as "box_1, box_2, and so on?"
Reply With Quote  
bigpandesal bigpandesal is offline bigpandesal lives in United States 2008-05-06 #5 Old  
What Am I Doing Wrong
So I suck at this....Heres a link to my flash file....WHAT AM I DOING WRONG AHHHH!
Flash Demo
Reply With Quote  
bigpandesal bigpandesal is offline bigpandesal lives in United States 2008-05-06 #6 Old  
OK I got it to work
The next dilemma I have is that I have them placed in certain area of the swf. Is it possible to indiviually manually place them on screen?
Reply With Quote  
Isocase's Avatar Isocase Isocase is offline Isocase lives in United States 2008-05-06 #7 Old  
You can move the entire container like container._x = ..., container._y = ... or you can grab each box individually like container[ "box_" + 0 ]._x = ..., container["box_" + 1]._x = ...
Reply With Quote  
pixcels pixcels is offline 2008-09-12 #8 Old  
Is there any way to make this work inside of XML when you load an XML file and have a group of buttons on the page.
Reply With Quote  
Thread Tools
Display Modes Rate This Thread
Rate This Thread: