Thursday, 10 April 2014

Working Processes: Creating the Game - Problems with scripting the drawers

When working on the drawers section, I made 4 versions of the drawers. They were as follows:

All closed
1st one open
2nd one open
3rd one open

I created the script:

drawerView.drawer1.addEventListener(MouseEvent.CLICK,drawer1Listener);
function drawer1Listener(ev:MouseEvent):void{
    drawerView.gotoAndStop("opened1");
}
drawerView.drawer2.addEventListener(MouseEvent.CLICK,drawer2Listener);
function drawer2Listener(ev:MouseEvent):void{
    drawerView.gotoAndStop("opened2");
}
drawerView.drawer3.addEventListener(MouseEvent.CLICK,drawer3Listener);
function drawer3Listener(ev:MouseEvent):void{
    drawerView.gotoAndStop("opened3");
}



and put it outside of the movieclips.

When testing the the Flash SWF, I noticed that the drawers were only able to be opened once.



I decided to add traces in for each time a drawer was opened to see if this could help me solve the problem.

In the end, I decided it was best to firstly, make sure that the buttons for all the drawers were available on all frames of the movieclip, whether they were accessible or not, so that they can still be read by Flash. Secondly, I modified the code to recall the listeners for the other drawers after one had been opened. This fixed the problem. My new code looked like this:

drawerView.drawer1.addEventListener(MouseEvent.CLICK,drawer1Listener);
function drawer1Listener(ev:MouseEvent):void{
    drawerView.gotoAndStop("opened1");
    drawerView.drawer2.addEventListener(MouseEvent.CLICK,drawer2Listener);
    drawerView.drawer3.addEventListener(MouseEvent.CLICK,drawer3Listener);
}
drawerView.drawer2.addEventListener(MouseEvent.CLICK,drawer2Listener);
function drawer2Listener(ev:MouseEvent):void{
    drawerView.gotoAndStop("opened2");
    drawerView.drawer1.addEventListener(MouseEvent.CLICK,drawer1Listener);
    drawerView.drawer3.addEventListener(MouseEvent.CLICK,drawer3Listener);
}
drawerView.drawer3.addEventListener(MouseEvent.CLICK,drawer3Listener);
function drawer3Listener(ev:MouseEvent):void{
    drawerView.gotoAndStop("opened3");
    drawerView.drawer2.addEventListener(MouseEvent.CLICK,drawer2Listener);
    drawerView.drawer1.addEventListener(MouseEvent.CLICK,drawer1Listener);
}


.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.