0
\$\begingroup\$

I am having difficulties creating a button that has Dynamic text in it for my interactive quiz game.

The text on the button has to change to show a selectable answer based off of what the current question is.

I have this all working well with plain dynamic text fields (and multidimensional arrays) but when I try getting it to work in a button, flash doesn't recognize the textfield that I placed in the button and I get an error.

After doing some googleing I learned that it is normal for flash to not link to a textfield within a button movieclip.

I would be happy if there any strategies that you could suggest for me to achieve Dynamic Text Buttons.

Thanks! Graeme

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

Just use a MovieClip instead of a button. You can still draw your button-states as different frames on the timeline and use ActionScript to trigger the correct behavior. You could even write a new base-class for your buttons that you can then apply to all your buttons.

Here's how such a class (McButton.as) could look like:

package  {
    import flash.display.MovieClip;
    import flash.events.MouseEvent;

    /**
     * Simulate button behavior with a MovieClip.
     * This assumes:
     * - normal state on frame 1
     * - rollover on frame 2 
     * - active on frame 3
     */
    public class McButton extends MovieClip {

        public function McButton() 
        {
            super();
            mouseChildren = false;
            useHandCursor = buttonMode = true;

            addEventListener(MouseEvent.ROLL_OVER, handleMouse, false, 0, true);
            addEventListener(MouseEvent.ROLL_OUT, handleMouse, false, 0, true);
            addEventListener(MouseEvent.MOUSE_DOWN, handleMouse, false, 0, true);
            addEventListener(MouseEvent.MOUSE_UP, handleMouse, false, 0, true);

            gotoAndStop(1);
        }

        private function handleMouse(evt:MouseEvent):void
        {
            switch(evt.type){
                case MouseEvent.MOUSE_UP:
                case MouseEvent.ROLL_OVER:
                    gotoAndStop(2);
                    break;

                case MouseEvent.ROLL_OUT:
                    gotoAndStop(1);
                    break;

                case MouseEvent.MOUSE_DOWN:
                    gotoAndStop(3);
                    break;
            }
        }
    }
}

Then you just create your buttons as MovieClips in the Library and assign the McButton as their base-class (instead of flash.display.MovieClip), as seen in the following screenshot:

flash base class settings

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .