Skip to main content
Known Participant
June 25, 2009
Answered

Conditional Click States

  • June 25, 2009
  • 2 replies
  • 912 views

Hello, I have a brief kind of hit state question, I have a button hit state called btnWorkH, below is the start of my code to make it functional. The idea being, that when someone clicks the button, I add a child to the top, to make it look like it has been clicked and is maintaining an alternate color. How would I code this so that it becomes a toggle? As, I need a click (once this action has been performed) that removes the child... just not sure how to write the condition for this.

Thanks all!

btnWorkH.addEventListener (MouseEvent.CLICK, workClick);
                               
                               
function workClick (e:MouseEvent):void{
    addChild (workO);
    workO.x = 62.5;
    workO.y = 109.3;
   
    addChild (txtAmy);
    txtAmy.x = 105.1;
    txtAmy.y = 109.3;
   
}

This topic has been closed for replies.
Correct answer Ned Murphy

You can probably take a different approach and use a movieclip instead of a button.  That way you can avoid having to add anything with code to make it look clicked.  Just have it sit n it's clicked state frame.  Toggling it back off may be easier to manage because you have have the movieclip hold a status variable that you use in a conditional.

2 replies

Participant
June 25, 2009

I haven't tersted this, but it may help:

function workClick (e:MouseEvent):void{

// check to see if workO is backmost DisplayObject

if (e.target.getChildAt(0) == workO) {

     // it is, so bring it to the front
    addChild (workO);
    workO.x = 62.5;
    workO.y = 109.3;
} else {

     // it isn't, so bring txtAmy to the front
    addChild (txtAmy);
    txtAmy.x = 105.1;
    txtAmy.y = 109.3;

}

}

Hope this helps...

bamaurerAuthor
Known Participant
June 25, 2009

hmm, thanks for the suggestions, both seem helpful. Will give both a shot and see what sticks, much appreciated!

bamaurerAuthor
Known Participant
June 25, 2009

maybe i spoke to soon. Here is what I would like to do:

Again, have a link on the site (mc button).

When you click this, it should load more links, and also highlight orange – which I am doing via adding a child to the top. Now, you have an orange link, plus the 6 links it added via click (that is what the addChild txtAmy is...a sample of these).

So, I am assuming I can write that conditional suggested, and just let everything rely on whether or not the orange added child is on top or the bottom.

How would I establish that the child I need to add begins in the last position? So, I am assuming I will just add it when I add the main link, behind it, however, still not sure how I designate that it is ini the very back?

Then, I think it makes sense, but how do I designate the position of the child initially?

Ned, I do actually have a clicked state wtihin this movieclip, just not sure how to manage the toggling back and forth on and off of it... if that makes sense? this seems like the easiest way "For me," but I am sure I am wrong!

Ned Murphy
Ned MurphyCorrect answer
Legend
June 25, 2009

You can probably take a different approach and use a movieclip instead of a button.  That way you can avoid having to add anything with code to make it look clicked.  Just have it sit n it's clicked state frame.  Toggling it back off may be easier to manage because you have have the movieclip hold a status variable that you use in a conditional.