button help

Subscribe to button help 23 posts

avatar for phore_eyes phore_eyes 427 posts
Flag Post

how would i make it so that when you click on a button it then goes away and you cannot click it any more

 
avatar for Janck Janck 253 posts
Flag Post

Give your button an instance name, such as “genericbtn”.

In the button’s actions:

on (press) {
    ...
    ...
    genericbtn._visible = false
    ...
    ...
}
 
avatar for phore_eyes phore_eyes 427 posts
Flag Post

does this make it so you can’t click it or you can’t see it?

 
avatar for Janck Janck 253 posts
Flag Post

Both.

 
avatar for phore_eyes phore_eyes 427 posts
Flag Post

sweet thanks

 
avatar for yrudoy yrudoy 341 posts
Flag Post

I just move the button off of the screen. (:

 
avatar for Nabb Nabb 1002 posts
Flag Post

You can tab to an offscreen button ;)

 
avatar for yrudoy yrudoy 341 posts
Flag Post

):

 
avatar for phore_eyes phore_eyes 427 posts
Flag Post

sorry that code didn’t work for some reson any other help???

 
avatar for phore_eyes phore_eyes 427 posts
Flag Post

ok i got it so that the button is gone but when you go to the frame again it’s there again is there any way to make it stay gone

 
avatar for ch00se ch00se 98 posts
Flag Post

I’m not sure how you’re coding. If you’re using classes to store Object variables you can create a boolean variable that tracks when the button should be in a visible state, then just attach an if statement.

 
avatar for Nyde Nyde 25 posts
Flag Post

Going off on ch00se’s idea: a way you can hide your button and keep it hidden when it enters the frame again is doing the following:

Say you have a button with an instance name myButton. You can place the following block of AS in the same frame as your button.

var buttonVisibility:Boolean; //declare a boolean variable

if(buttonVisibility == undefined) {
	myButton._visible = true; //button hasn't been clicked yet
} else {
	myButton._visible = buttonVisibility; //if it's defined then hide the button	
}

// this function handles the button being clicked event
myButton.onRelease = function(): Void {
	buttonVisibility = false; //set the boolean to false
	myButton._visible = buttonVisibility; //immediately set visibility of the button to false
}



Just read the comments to see how it works. I tested this in Flash 8 and it works on my end. Let me know if this solves your issue.

 
avatar for phore_eyes phore_eyes 427 posts
Flag Post

sorry i havent replied yet i was out camping any ways when i use that code this comes up

Scene=Scene 1, Layer=back, Frame=167: Line 10: ‘{’ expected
myButton.onRelease = function(): Void {

Scene=Scene 1, Layer=back, Frame=167: Line 13: Unexpected ‘}’ encountered
}

any help here

 
avatar for Janck Janck 253 posts
Flag Post

Nyde, are you sure that

: Void

is completely necessary?

 
avatar for arcaneCoder arcaneCoder 2354 posts
Flag Post

@Janck: “:Void” just indicates that the function doesnt return anything. Its actually good practice to put that.

 
avatar for Janck Janck 253 posts
Flag Post

It makes sense, but it seems that phore_eyes’ flash doesn’t like it, though.

 
avatar for phore_eyes phore_eyes 427 posts
Flag Post

so i should try taking : void out???

 
avatar for Nyde Nyde 25 posts
Flag Post

@Janck: it will work without “Void” — but just because it works, doesn’t mean it’s the best way to do it. I put that there because, like arcaneCoder said, the function isn’t returning anything.

@phore_eyes: What version of Flash are you using? I guess try “function() {}” instead of “function(): Void {}”… or try and take out the space in between the semi-colon and Void.

 
avatar for Nyde Nyde 25 posts
Flag Post

Just an aside: can anyone think of a better way to do this? I really hate checking to see if a variable is “undefined” in that “if” statement.

 
avatar for phore_eyes phore_eyes 427 posts
Flag Post

i’m useing flash mx

 
avatar for JudeMaverick JudeMaverick 8844 posts
Flag Post

Flash MX is outdated. Our flash are mainly Flash 8 and Flash CS3.

 
avatar for Janck Janck 253 posts
Flag Post

Be careful of updating too much. You’ll lose Wii compatibility.

 
avatar for JudeMaverick JudeMaverick 8844 posts
Flag Post

It’s Adobe’s fault that “external things need to be added so they can use Flash Player 8 and above”. It’s also Adobe’s fault that 2DArray’s newest game, Chatmaster, took a long time to publish >:(