View Full Version : single instance button (a follow-up)
kalasnjikov
02-07-2006, 04:12 PM
this is a continuation of a post from a couple days ago. i'm trying to create a button that deactivates itself after its first interaction. i received some advice from oldnewbie, but it didn't pan out (although i thought it had.):confused:
here's my code for what i have so far for a self-disenabling button:
//i assigned a global variable called pusht the value of 1 in the first frame
//(actions layer):
_global.pusht = 1;
//then i attached this code to the desired button instance in the first frame
// in the layer where i added the first instance of the button,
//named initialstate
on (release) {
pusht = pusht + 1;
if (pusht++ <= 2) {
gotoAndPlay(2);
} else
(initialstate.enabled = false);
}
this allows the button to function but it doesn't help with disabling the button after it's initial triggering. it would seem to make more sense to tie this variable to the frame in the _root timeline, but i can't find a way to call the timeline's position and create a variable based on it.
i'm a complete noob, so any help would be greatly appreciated.
flashead
02-07-2006, 04:23 PM
i usually save a local variable on the button that keeps track of whether it's been clicked or not. then i save a global variable of the the last button that was clicked so that i can re-enable it when another is clicked.
like this:
var lastClicked = null; // variable that stores the instance of the last button clicked
function onClick()
{
// 'select' is a variable that keeps track of whether this button has been selected
// this line does 2 things at once, it sets the 'select' variable to the opposite of itself and it checks to see if its 'true' or 'false'
if ( this.select = !this.select )
{
this.gotoAndStop( "released" );
lastClicked.gotoAndPlay( "out" );
lastClicked.select = false;
lastClicked = this; // set 'lastClicked' to equal this button
}
else
{
this.gotoAndPlay( "out" );
lastClicked = null;
}
}
myButton.onRelease = onClick;
here's a file to help you out too.
k.
kalasnjikov
02-07-2006, 09:31 PM
first let me say thanks alot for the help.
however, i'm not interpreting your code well. :( the terms "released" and "out" i don't understand. I was under the impression that those functions required a frame number as a parameter. what do your strings refer to?
also, i placed the text into my actions panel, and it seems to think that the first two and the last lines of script need to be "within the 'on' handler." am i missing something?
k
Chewie
02-07-2006, 09:37 PM
The strings refer to frame labels, it is always better to use frame labels rather than numbers.
kalasnjikov
02-07-2006, 10:03 PM
do you mean the instance name?
Chewie
02-07-2006, 10:05 PM
No, frame labels. Click on a frame and then look at the property inspector. There is a box where you can enter a label for the frame.
kalasnjikov
02-07-2006, 10:08 PM
oh, i see. that's quite helpful. thanks, chewie.
Chewie
02-07-2006, 10:14 PM
I always use labels, that way if you need to remove or add frames there is no need to modify your code. The label remains constant, whereas a frame number would change.
kalasnjikov
02-07-2006, 10:16 PM
thanks.:)
this still doesn't quite help, however.:o
i don't want to direct the button between two different frames. the button should only do one thing, and once it's fufilled it's job it should be inactive, though still visible.
also, i'm still getting that error message about the first two and last lines of code needing to be within the on handler.
again, i must be missing something.
Chewie
02-07-2006, 10:24 PM
I am assuming you are putting the code on your button as you are using on handlers. For flasheads code to work it needs to be on the timeline that the button resides. Ypou also need to give your button an instance name myButton
kalasnjikov
02-07-2006, 10:44 PM
okay.
i had already used the instance name in my FLA. after i switched the code from the button to the timeline and layer that the button resides in, i still needed to label those frames. so i did.
no dice. do i still need the code attached to the button instance, or would that create a problem?
kalasnjikov
02-07-2006, 10:59 PM
so, yeah. got the instance name. and moved the code to the timeline. but it still isn't responding. i think the frame label has something to do with it.
why do frame labels seem to want to extend through a tween?
flashead
02-08-2006, 03:40 PM
i attached a file with my last post which shows how to properly use the code i gave you. but you can't expect to just paste that code into your file and have it work unless everything is set up as it is in my file.
i just posted that code so you could study it and understand the concept behind it. i didn't mean for you to paste it directly into your file and have it work. you'll almost always have to tweak code given to you in the forums, to make it work in your file.
k.
kalasnjikov
02-08-2006, 03:57 PM
hello,
yes, thanks so much. i downloaded your .zip file. and although i am a novice at actionscript, i am actually not retarded, but rather quite intelligent, as you may have grasped in reading my somehwhat verbose posts. :rolleyes:
that said, i am still having trouble parsing your script. it is simply because i am not highly proficient in the syntax or vocabulary of the actionscript language, since i am endeavoring to learn it from two books, with no formal instruction, a decidely foolish and tedious affair.
however, i thank you for your help. and i will continue to go over your script to discover its secrets, which i'm sure may seem quite obvious to you, though to me it has all the transparency of granite, despite your honorable efforts to enlighten me.
again, thank you:)
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.