ok, new problem. I've created some buttons that essentially i have created for a quiz page. What i've designed them to do is when you click on them they should change in to their hit state and do nothing else. The yes buttons should show a tick on the hit state and the no buttons should show a cross on the hit state. Except that they do not change at all, what is wrong with them?

Dani AI

Generated

This thread illustrates a common Flash misunderstanding: the Button symbol's "hit" frame is not a visible state — it only defines the clickable area. That is why visually putting a tick/cross into the Hit frame has no effect at runtime. The solution is to use a visible state (a MovieClip frame or a separate child clip) and switch that on click, then prevent further clicks so the state remains.

A scalable pattern is to convert each answer to a MovieClip with labeled frames (for example normal, correct, wrong), give each instance a simple property (or maintain a mapping) that marks the correct answer, and use one event handler to switch frames and disable the question after selection. This avoids repeating instance-specific code for every button.

var buttons:Array = [btnA, btnB, btnC, btnD];

for each (var b:MovieClip in buttons) {
    b.buttonMode = true;
    b.mouseChildren = false;
    b.addEventListener(MouseEvent.CLICK, onPick);
}

function onPick(e:MouseEvent):void {
    var picked:MovieClip = e.currentTarget as MovieClip;
    var isCorrect:Boolean = Boolean(picked.correct); // assign in code or IDE
    picked.gotoAndStop(isCorrect ? "correct" : "wrong");
    for each (var nb:MovieClip in buttons) {
        nb.removeEventListener(MouseEvent.CLICK, onPick);
        nb.mouseEnabled = false;
    }
}

Troubleshooting: make sure the symbol is a MovieClip (not a Button), label frames and call stop() on clips if their timelines advance, ensure instance names are set in the Properties panel, and test that you are adding listeners to the actual instances. In this thread described the symptom and provided a working fix; the pattern above keeps the code concise and scalable for many answers.

Recommended Answers

All 7 Replies

Member Avatar for Member #334542

You did not written any code for that and too there is no instance name of your hits and where is the event listeners?

what i want to happen is that i want then to stay in their hit state once they have been clicked. Just like a quiz, so that when they click the correct button it shows its hit state of a tick over it and when they click a wrong button it shows an x over it

Member Avatar for Member #334542

Thats Right Man! where is the code and the instance name for your hit state buttons?

ok ive attached the code and added in the instance name so that they operate fine. However still not sure how to make them stay in their hit state.
have a look at what ive done in attachement for clarity.

Member Avatar for Member #334542

Hey, you done in a wrong way. You utilized the hit button without knowing the purpose of that!. fine leave it.

I have attached a file for your solution, make it in that way. It will work.

Hope this solve!

ahh yes, thank you, that did work. i am very grateful for what you have done. its ashame i have to give a new instance name and attache3d code for every 20 quiz buttons that you created for me to work.

Member Avatar for Member #334542

Cheers!! Go ahead!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.