MovieClip as button using labels to go to frame automatically.
Posted on 02. Apr, 2009 by thornyeternity in ActionScript 3 Snippets
Adobe says – and some blog I saw – that one can have a 3 frame movie clip with a stop action in the first frame, and “_up”,”_over”,”_down” labels in that order at each of the 3 frames, and once a listener is added (for any type of mouse event) it will automatically do as a SimpleButton would. No go.
Then I found blogs that had gotoAndStops which just could not be right.
The trick – ensure the frame (or easier, the whole thing) has its mouseChildren set to false.
Added onto this – a way to use one function for all the events:
private var test_mc:linked_btn = new linked_btn();
addChild(test_mc);
test_mc.addEventListener(MouseEvent.MOUSE_DOWN, checking);//re-use function and check for event type
test_mc.addEventListener(MouseEvent.MOUSE_OVER, checking);
test_mc.addEventListener(MouseEvent.MOUSE_OUT, checking);
test_mc.addEventListener(MouseEvent.MOUSE_UP, checking);
test_mc.buttonMode = true;
test_mc.mouseChildren = false;
//adobe documentation: If you include frames labeled _up, _over, and _down, Flash Player provides automatic state changes
//must do else will not do state changes – else bubbling down to look for more event listeners probably
//solution: http://www.flashfocus.nl
private function checking(event:MouseEvent):void{
trace(event.type);
if(event.type==”mouseOver”){
trace(“over script”);
}else if(event.type==”mouseOut”){
trace(“out script”);
}else if(event.type==”mouseDown”){
trace(“down script”);
}else if(event.type==”mouseUp”){
trace(“up script”);
}
}


