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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

functions joining together?

Status
Not open for further replies.

blaablaa69

Technical User
Feb 15, 2005
57
AU
i have used the following code for a menu script. basically when one of the menu items is selected, i want the other 4 to fade off. when i have just one of the functions, and one onmouseup command, it works, but when i add in the rest they all fade off at once? can some pls help?



stop();
var startpos = 198;
var currentpos = 0;
var prevpos = 0;
var startscale = 140;
var currentscale = 0;
_root.slide._x = 780;
var toggle = Boolean(false);
var section = "home";

var easeType = mx.transitions.easing.None.easeNone;
var time = 1;

function one() {
_root.section = "profile";
_root.products._alpha = "100";
startAlphaTween = new mx.transitions.Tween(whyus, "_alpha", easeType, 100, 0, time, true);
startAlphaTween = new mx.transitions.Tween(products, "_alpha", easeType, 100, 0, time, true);
startAlphaTween = new mx.transitions.Tween(contactus, "_alpha", easeType, 100, 0, time, true);
startAlphaTween = new mx.transitions.Tween(catalogue, "_alpha", easeType, 100, 0, time, true);
};

function two() {
_root.section = "whyus";
_root.whyus._alpha = "100";
startAlphaTween = new mx.transitions.Tween(profile, "_alpha", easeType, 100, 0, time, true);
startAlphaTween = new mx.transitions.Tween(products, "_alpha", easeType, 100, 0, time, true);
startAlphaTween = new mx.transitions.Tween(contactus, "_alpha", easeType, 100, 0, time, true);
startAlphaTween = new mx.transitions.Tween(catalogue, "_alpha", easeType, 100, 0, time, true);
};

function three() {
_root.section = "products";
_root.whyus._alpha = "100";
startAlphaTween = new mx.transitions.Tween(profile, "_alpha", easeType, 100, 0, time, true);
startAlphaTween = new mx.transitions.Tween(whyus, "_alpha", easeType, 100, 0, time, true);
startAlphaTween = new mx.transitions.Tween(contactus, "_alpha", easeType, 100, 0, time, true);
startAlphaTween = new mx.transitions.Tween(catalogue, "_alpha", easeType, 100, 0, time, true);
};

function four() {
_root.section = "contactus";
_root.whyus._alpha = "100";
startAlphaTween = new mx.transitions.Tween(profile, "_alpha", easeType, 100, 0, time, true);
startAlphaTween = new mx.transitions.Tween(whyus, "_alpha", easeType, 100, 0, time, true);
startAlphaTween = new mx.transitions.Tween(products, "_alpha", easeType, 100, 0, time, true);
startAlphaTween = new mx.transitions.Tween(catalogue, "_alpha", easeType, 100, 0, time, true);
};

function five() {
_root.section = "catalogue";
_root.whyus._alpha = "100";
startAlphaTween = new mx.transitions.Tween(profile, "_alpha", easeType, 100, 0, time, true);
startAlphaTween = new mx.transitions.Tween(whyus, "_alpha", easeType, 100, 0, time, true);
startAlphaTween = new mx.transitions.Tween(products, "_alpha", easeType, 100, 0, time, true);
startAlphaTween = new mx.transitions.Tween(contactus, "_alpha", easeType, 100, 0, time, true);
};

_root.profile.onMouseUp = function () {
one();
};
_root.whyus.onMouseUp = function () {
two();
};
_root.products.onMouseUp = function () {
three();
};
_root.contactus.onMouseUp = function () {
four();
};
_root.catalogue.onMouseUp = function () {
five();
};
 
if i only use one onMouseUp condition, it works so i dont think its the functions? anyone have any ideas? or another way i can do it please?
 
What about if i change it around a have just one function. There would be an array of the 5 items. When the function was called, a variable would be passed to say exclude this entry, but make all the rest in the array fade off. Would that be a better way? I know how to set up the array and function, but how would a say "exclude this entry, but include the rest?
 
ok ive changed it around with the for loop. so it goes like this.


function output(arr, sec) {
len = arr.length;
for(var i=0; i<len; i++) {
if(i == sec) {
this.arr.gotoAndStop("5");
} else {
this.arr.gotoAndStop("10");
}
}
}


var section = new Array();
section[0] = "profile";
section[1] = "whyus";
section[2] = "products";
section[3] = "contactus";
section[4] = "catalogue";

output(section, 2);



But this doesnt work! Im pretty sure its because of the line
this.arr.gotoAndStop("5");
as its looking for an object named "arr" instead of inserting that variable.
Does anyone have any ideas on how to get it to work? Any replys would be appreciated!
 
I've just looked at your first code. If I understood your intention correctly, the whole thing can be expressed as follows:

[tt]//
import mx.transitions.Tween;
var easeType:Function = mx.transitions.easing.None.easeNone;
var time:Number = 1;
var menuItems:Array = ["profile", "whyus", "products", "contactus", "catalogue"];
for (var i = 0; i<5; i++) {
this[menuItems].onPress = function() {
for (var j = 0; j<5; j++) {
var mc:MovieClip = this._parent[menuItems[j]];
mc._alpha = 100;
if (mc != this) {
new Tween(mc, "_alpha", easeType, 100, 0, time, true);
}
}
};
}
stop();
//[/tt]

This is much shorter (16 lines instead of 50+ lines). If this is not what you're after, let me know.

Kenneth Kawamoto
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top