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

function for buttons 2

Status
Not open for further replies.

wikfx

IS-IT--Management
Dec 16, 2001
196
MT
Hi all I am creating a menu for a website I am doing 10 links so it will have 10 buttons, I can hard code each button like this:

// Button 1
// Button Label
link1.bar.txtlabel = "Home";
link1.onRollOver = function (){
link1.ball.play();
};
link1.onPress = function () {
link1.bar._y = 1
this.gotoAndStop(link1);
};
link1.onRollOut = function () {
link1.ball.stop();
link1.bar._y = 0;
};
link1.onRelease = function () {
link1.ball.stop();
link1.bar._y = 0;
};

but I would like to do a Function that holds that stuff in it so that I can use the code once as a template instead of doing it 10 times so if I wanna change anything I can do it just once. anyway here is the function I tried to do but it didnt rerally work:

function MenuLink(sLink:String, sTitle:String) : Void{

[link+sLink]bar.txtlabel = sTitle;

[link + sLink]onRollOver = function (){
[link + sLink]ball.play();
};

[link + sLink]onPress = function () {
[link + sLink]bar._y = 1
this.gotoAndStop(link + sLink);
};

[link + sLinkNum]onRollOut = function () {
[link + sLink]ball.stop();
[link + sLink]bar._y = 0;
};

[link + sLink]onRelease = function () {
[link + sLink]ball.stop();
[link + sLink]bar._y = 0;
};

trace("Link " + sLink + " Title: " + sTitle);
}

MenuLink("1", "One");
MenuLink("2", "Two");
MenuLink("3", "Three");
MenuLink("4", "Four");
MenuLink("5", "Five");
MenuLink("6", "Six");
MenuLink("7", "Seven");
MenuLink("8", "Eight");
MenuLink("9", "Nine");
MenuLink("10", "Ten");

it would be great if someone could help me :)

Thanks A Million Guys
Brian
 
I assuming you are using mc's as buttons?...try this:

MovieClip.prototype.buttonAll = function() {
//would need to see a vaiable for the text
//I used this._name which would mean you
//change your MC instance name to Home
//in this situation
this.bar.txtlabel = "Home";//would become this._name
this.onRollOver = function() {
this.ball.play();
};
this.onPress = function() {
this.bar._y = 1;
this.gotoAndStop(link1);
};
this.onRollOut = function() {
this.ball.stop();
this.bar._y = 0;
};
this.onRelease = function() {
this.ball.stop();
this.bar._y = 0;
};
};
link1.buttonAll()
link2.buttonAll()
link3.buttonAll()
link4.buttonAll()
link5.buttonAll()
link6.buttonAll()
link7.buttonAll()
link8.buttonAll()
link9.buttonAll()
link10.buttonAll()

Adam
 
This is something I could use too - is there a fla available?

idaryl
idface.gif
 
I could make you one...what do you want your mc's to do, when rolled over and such?

Adam
 
hey Adam;
thamks a billion great work man I got the thing workin I just have one last little problem, here is the code I marked where the problem is with PROBLEM HERE I think you can see it anyway on that line the gotoAndStop(Link1); statement refers to a frame label where Link1 is the name of that frame I have a frame label for each button where it trigers another animation, its not going to the corresponding frame for me , I tried to set a var in the function but maybe I aint doin it right, any ideas? and thanks again for the great help.

MovieClip.prototype.buttonAll = function() {
//would need to see a vaiable for the text
//I used this._name which would mean you
//change your MC instance name to Home
//in this situation
this.bar.txtlabel = "Home";//would become this._name
this.onRollOver = function() {
this.ball.play();
};
this.onPress = function() {
this.bar._y = 1;
this.gotoAndStop(Link1); //<---- PROBLEM HERE <----
};
this.onRollOut = function() {
this.ball.stop();
this.bar._y = 0;
};
this.onRelease = function() {
this.ball.stop();
this.bar._y = 0;
};
};
Link1.buttonAll()
Link2.buttonAll()
Link3.buttonAll()
Link4.buttonAll()
Link5.buttonAll()
Link6.buttonAll()
Link7.buttonAll()
Link8.buttonAll()
Link9.buttonAll()
Link10.buttonAll()


Thanks a mill
Brian
 
if your frame has a label that is the same as the movie clip instance name you can use:

this.gotoAndPlay(this._name)

Adam
 
cool thanks I tried that and it worked but I had to remove the this. from the beginning so it looks like this:
gotoAndPlay(this._name);

anyway thank you so much again,
Brian
 
no problem, the "this" refers to the movieclip you pressed...I thought your labeled frame was in that clip...anyway, glad it worked for ya ;)

Adam
 
Do not be afraid to click the button recognizing Adam14's post as helpful (which it obviously was).

Wow JT that almost looked like you knew what you were doing!
 
...
You don't need to be the one who asked the question to vote ...
 
Who should it have been?

Wow JT that almost looked like you knew what you were doing!
 
Want me to vote for you in every thread you've ever answered? That can be arranged!
 
hey Adam sorry I didnt click the link with the star, OK guys call me STUPID I actually never noticed that little link :( sorry guys well know I know and I will use it more often as I always got great help from mostly adam and oldnewbie sorry again guys and thanks a million :)

Brian
 
I don't know where you got that from Old. I would not want anyone to vote just because a reply was made. This particular post was (obviously) helpful to Wikpod and it was an appropriate comment on my part.

You are never one to mince words when you think someone should vote... it is interesting that you would think that my doing so is a problem.

What's up with that?!

Wow JT that almost looked like you knew what you were doing!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top