View Full Version : Button Question
vox98
04-04-2004, 12:37 PM
hey everyone,
Can anyone explain how you would disable a button after its been pressed?
I want it so when someone clicks a button they cant press it again to load the same movie.
Any help is much appreciated.
Oldnewbie has tried helping with this, and while Im sure this is correct, i dont understand it.
on(release){
if(_level0.current_selection == "section1"){ // or "home" or whatever...
stop(); // do nothing...
} else {
//the script you already had...
//+ setting the variable...
_level0.current_selection = "section1";
}
}
Ruben
04-04-2004, 12:46 PM
Hm....I guess it would work, and I don't really see what's so hard, seems like OldNewbie left enough comment...
Anyways...Why not do something like this [let's say you'd have 2 buttons and if you'd press button 1 it'd go disabled, the same voor button 2]:
button1.onRelease = function(){
_root["button"+disabledbutton]._enabled = true; // enable the disabled button
_root.button1._enabled = false; // disable this button
disabledbutton = 1; // let the movie know what button is disabled now
// and of course the actions you'd want the button to take
}
button2.onRelease = function(){ _root["button"+disabledbutton]._enabled = true; // enable the disabled button
_root.button2._enabled = false; // disable this button
disabledbutton = 2; // let the movie know what button is disabled now
// and of course the actions you'd want the button to take
}
Wouldn't that be more simple??
- Ruben
EDIT: Just saying '["button"+disabledbutton]._x' won't work, you always have to do somethings like:
_root["button"+disabledbutton]._x
_parent["button"+disabledbutton]._x
this["button"+disabledbutton]._x
somemovieclip["button"+disabledbutton]._x
Don't forget to leave the dot: 'this.["button"+disabledbutton]._x' won't work either. See Jesse's advanced pathing tutorial (http://www.actionscript.org/tutorials/intermediate/advanced_pathing/index.shtml) for more info....
vox98
04-04-2004, 01:39 PM
thanx for the reply ruben. Ya I guess he did leave good description but im not great when it comes to actionscript. With the code you had posted, where do i add this to? the buttons or a frame? still pretty lost.
Ruben
04-04-2004, 01:56 PM
:p You place some buttons on the stage with instance names "button1" and "button2" and then you place the script on the frame...
Anyways, was the script clear enought for you?
- Ruben
vox98
04-04-2004, 03:24 PM
your script does make sense but here is where it will get me. the buttons are all in seperate MC's. They all have the rollover and rollout effect, so when you rollover a button it fades in and when you rollout it fades out. In order to do that effect there are invisible buttons in each seperate MC placed over another MC which has the fade effects. which im sure you already know how to do that. But i have tried placing the code on a frame in the MC where the actual hit state is, but cant get it to work.
Ruben
04-04-2004, 03:29 PM
Before I'm going to reshape the script: When a button is clicked, do you still want it to fade and stuff??
- Ruben
vox98
04-04-2004, 03:31 PM
well id kinda like it to keep the fade in on stop until another button is pressed.
Ruben
04-04-2004, 03:39 PM
So if I get it right [the 2button example again ;)]:
- In the beginning both buttons fade in on rollon and fade out on rollout;
- When button1 is clicked only button2 fades in and out on rollon and rollout;
- When button2 is clicked only button1 fades in and out on rollon and rollout;
Right? - Ruben
vox98
04-04-2004, 03:42 PM
correct! ;)
Ruben
04-04-2004, 03:54 PM
:D I guess we'll just have to kinda kill the script then ;)
OK, here it goes...This would be the script for inside of the mc [in which the invisible button is placed]:
button1.onRelease = function(){
_root.disabled = 1;
}
button1.onRollOver = function(){
if (_root.disabled != 1){
// here the actions that create fade-in
}
}
button1.onRollOut = function(){
if (_root.disabled != 1){
// here the actions that create fade-out
}
}
So it turns out this is pretty much the same as what oldnewbie gave you...
- Ruben
vox98
04-04-2004, 04:06 PM
ruben i must apologize now. I should have posted what code i have on the button before so you know.
this is what is on the invisible button:
on (rollOver) {
if (Number(_currentframe) == 1) {
gotoAndPlay(2);
} else if (Number(_currentframe) == 7) {
stop();
} else {
gotoAndPlay(15-_currentframe);
}
}
on (rollOut) {
if (Number(_currentframe) == 7) {
gotoAndPlay(8);
} else {
gotoAndPlay(15-_currentframe);
}
}
on (release) {
//unload Movie Behavior
if(this._parent._parent.mcHolder == Number(this._parent._parent.mcHolder)){
unloadMovieNum(this._parent._parent.mcHolder);
} else {
this._parent._parent.mcHolder.unloadMovie();
}
//End Behavior
//load Movie Behavior
if(this._parent._parent.mcHolder == Number(this._parent._parent.mcHolder)){
loadMovieNum("about.swf",this._parent._parent.mcHolder);
} else {
this._parent._parent.mcHolder.loadMovie("about.swf");
}
//End Behavior
//Movieclip GotoAndPlay Behavior
this._parent._parent.myPhotoClip.gotoAndPlay("tiger");
//End Behavior
}
Still having trouble implementing your code. ive tried adding it to the code on the button and also on the first frame but still a no go.
Ruben
04-04-2004, 05:12 PM
Hm....I've been trying to modify the script but things got a little messy.
It might be easier if you'd do something like this:
1. Create a new layer inside of the movieclip with the exact same graphics, make sure it's on top;
2. Turn the graphics on the new layer into a movieclip, let's call it "newGraphicsMC" and set its _alpha to 0;
3. Give each main movieclip [NOT "newGraphicsMC"] a seperate id, called 'mcid' [so for the first fade-button 1, the second 2, etc];
4. Create a new layer inside of "newGraphicsMC" with the following script:
// script for frame 1:
if (_parent.mcid == _root.disabled){
_alpha = 100;
}else{
_alpha = 0;
}
// script for frame 2:
gotoAndPlay(_currentframe-1)
5. And put this script on the button [modified version of your script ;)]:
on (rollOver) {
if (Number(_currentframe) == 1) {
gotoAndPlay(2);
} else if (Number(_currentframe) == 7) {
stop();
} else {
gotoAndPlay(15-_currentframe);
}
}
on (rollOut) {
if (Number(_currentframe) == 7) {
gotoAndPlay(8);
} else {
gotoAndPlay(15-_currentframe);
}
}
on (release) {
if (mcid != _root.disabled){
_root.disabled = mcid;
//unload Movie Behavior
if(this._parent._parent.mcHolder == Number(this._parent._parent.mcHolder)){
unloadMovieNum(this._parent._parent.mcHolder);
} else {
this._parent._parent.mcHolder.unloadMovie();
}
//End Behavior
//load Movie Behavior
if(this._parent._parent.mcHolder == Number(this._parent._parent.mcHolder)){
loadMovieNum("about.swf",this._parent._parent.mcHolder);
} else {
this._parent._parent.mcHolder.loadMovie("about.swf");
}
//End Behavior
//Movieclip GotoAndPlay Behavior
this._parent._parent.myPhotoClip.gotoAndPlay("tiger");
//End Behavior
}
}
That should do it
Good luck - Ruben
PS. You're hierarchy should look something like this:
_root:
menu-button1:
newGraphicsMC
invisiblebutton
menu-button2:
newGraphicsMC
invisiblebutton
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.