views:

17

answers:

1

I have an action script 2.0 request.

i have a flash movie with 7 check boxes. when the user has selcted a total of 4 check boxes the flash movie goes to another frame.

pretty simple

i'll contain all the checkboxes in a movie clip called mcCheckBox.

I just need to the code to make it go to a new frame once four check boxes have been selected.

thanks

A: 

you need to create a counter that is incremented each time a checkbox is clicked , when the counter value is 4 , go to the next frame.

also you may have to keep an array of the boxes have been checked, in case a second click unchecks the box , in which case you would decrement the counter.

edit:

i don't use as2 , so i can only give you an example in as3... i've added an Array of all the checkboxes names in order to filter the click events, if you click outside a checkbox, the event would be registered but you don't want to proceed with the code

import flash.events.MouseEvent;

var counter:int;
var allNames:Array = ['cb1', 'cb2' , 'cb3' , 'cb4'];
var boxesList:Array = [];

stop();
addEventListener(MouseEvent.CLICK , clickHandler );

function clickHandler(event:MouseEvent):void
{
    var boxName:String = event.target.name;

    //make sure the target is one of the checkboxes
    if(allNames.indexOf(boxName ) != -1 )
        updateCounter(boxName);

}

function updateCounter(bName:String):void
{   
    var index:int = boxesList.indexOf(bName);
    if( index == -1 )
    {
        //add to the list of checked boxes
        boxesList.push(bName );

        //increment counter
        ++counter;

    }else{
        //remove from the list of check boxes
        boxesList.splice(index , 1 );

        //decrement counter
        --counter;
    }

    if(counter == 4 )
       gotoAndStop('nextFrame');

   trace( counter );
}
PatrickS
thats exactly right, unfortunatly im not to good with the code part. And i dont really know how to go about writting this. Any sort of example code that i could work with would be great.
thats awesome, i'll check it out. thanks mate, i could never5 have written this.