Skip to main content
February 16, 2009
Question

Flash button with dynamic text

  • February 16, 2009
  • 2 replies
  • 798 views
I'm trying to create a flash button so that it can toggle between "Sound On" and "Sound Off" but I feel like I'm doing something wrong and it errors out on me.

I have a button on stage as, and in my up/over/down/hit in different colors I have a dynamic text field identified as sound_txt.

Here's the script I have so far for my frame:

stop();
mutebtn.addEventListener(MouseEvent.CLICK,muteDo);
function muteDo(event:MouseEvent) {
if (mutebtn.sound_txt.text == "Sound Off") {
mutebtn.sound_txt.text = "Sound On";
} else {
mutebtn.sound_txt.text = "Sound Off";
}
}

and this is the error message I am getting:

TypeError: Error #1010: A term is undefined and has no properties.
at buttontst_fla::MainTimeline/muteDo()
TypeError: Error #1010: A term is undefined and has no properties.
at buttontst_fla::MainTimeline/muteDo()

Can someboy please advise as to how I can get this to work?
This topic has been closed for replies.

2 replies

February 16, 2009
I tried bringing the textfield out of the button but while it worked when I pressed the button portion that is not under the text, it was the part of the text that got in the way from doing anything. I wonder where I can find an existing example that works the way I want it too so I can at least follow that example. I think I tried making the dynamic text a movie clip but was still getting similar errors.

Edit: I at least got it to work by converting the button into a movie clip although I had also wanted it so that I could also change the foreground color of the dynamic text upon rollover, etc.
Ned Murphy
Legend
February 16, 2009
The problem with having the textfield on top can be solved by making the textfield nonselectable. (I think mouseEnabled = false works too)

For the movieclip approach, you can mimic a button by having rollover and down states as frames which you go to during those events. Since you know how a button has 4 frames to work with, you essentially just need to mimic that in the movieclip, using ROLL_OVER / ROLL_OUT event handlers to move it across the frames.
Craig Grummitt
Inspiring
February 16, 2009
really? weird. through my experiments, you should be getting
"1119: Access of possibly undefined property sound_txt through a reference with static type flash.display:SimpleButton.", not "TypeError: Error #1010: A term is undefined and has no properties.
at buttontst_fla::MainTimeline/muteDo()"

The SimpleButton Class is static, so you can't reference a dynamic textField within it. either convert it to a MovieClip and handle the rollover states yourself, or bring the textField out of the button, so you can refer to it.