PDA

View Full Version : Locking a "button" (mc)



spmc
October 9th, 2008, 11:25 AM
I have 4 buttons being read in via XML. All fine and dandy work well, almost do what they're supposed to do.

What I'm trying to add to their functionality is a lock on the one that was just clicked. Used to be able to do it in AS2 but taking my first crack at AS3, it's not working. Want to lock the button that the user just click (swap out graphics to indicate locked state) and have the other 3 remaining buttons active. If user clicks one of the other three buttons, the current locked button unlocks and the newly clicked button locks.

Here is what I have so far, I know I'm missing parts, just can't get what those missing parts are.


function myRelease(e:MouseEvent):void {

e.currentTarget.buttonMode = false;
e.currentTarget.mouseEnabled = false;
e.currentTarget.gotoAndStop("_down");
e.currentTarget.watchNow.gotoAndStop("_down");

}

Any help would be greatly appreciated.

spmc
October 9th, 2008, 02:33 PM
Creatify just helped with this offline. I wanted to share because it has given me a headache and I'd like to help others avoid the headache. Thanks Creatify!

The Over, Out and release functions in case any of you are interested.


var lockedBtn:MovieClip = null;


function epOver(e:MouseEvent):void {
e.currentTarget.gotoAndStop("_over");
}

function epOut(e:MouseEvent):void {
//Checking if a button has been locked in epRel and if so keeping the states in the down mode
if(e.currentTarget==lockedBtn) {
e.currentTarget.gotoAndStop("_down");
e.currentTarget.watchNow.gotoAndStop("_down");

// If no button is locked this sends the rolled over button to the up state after rollOut
} else {
e.currentTarget.gotoAndStop("_up");
e.currentTarget.watchNow.gotoAndStop("_up");
}
}

function epRel(e:MouseEvent):void {
// First check to see if anything is locked and if so unlock it and lock the new item
if(lockedBtn) {
lockedBtn.mouseEnabled = true;
lockedBtn.buttonMode = true;
lockedBtn.gotoAndStop("_up");
lockedBtn.watchNow.gotoAndStop("_up");
}
e.currentTarget.gotoAndStop("_down");
e.currentTarget.watchNow.gotoAndStop("_down");
e.currentTarget.buttonMode = false;
e.currentTarget.mouseEnabled = false;

//a typecast thing. e.currentTarget is an object on the canvas, but you gotta tell flash to use it as MovieClip
lockedBtn = e.currentTarget as MovieClip;

}

snickelfritz
October 9th, 2008, 11:50 PM
The following script works for me.

// button instance names are "b1" "b2" "b3" "b4"
function btnClick(event:MouseEvent)
{
for (var i:Number = 1; i <= 4; i++)
{
this["b" + i].mouseEnabled = true;
}
event.target.mouseEnabled = false;
}