button help

23 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

 
Flag Post

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

In the button’s actions:

on (press) {
    ...
    ...
    genericbtn._visible = false
    ...
    ...
}
 
Flag Post

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

 
Flag Post

Both.

 
Flag Post

sweet thanks

 
Flag Post

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

 
Flag Post

You can tab to an offscreen button ;)

 
Flag Post

):

 
Flag Post

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

 
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

 
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.

 
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.

 
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

 
Flag Post

Nyde, are you sure that

: Void

is completely necessary?

 
Flag Post

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

 
Flag Post

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

 
Flag Post

so i should try taking : void out???

 
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.

 
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.

 
Flag Post

i’m useing flash mx

 
Flag Post

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

 
Flag Post

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

 
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 >:(