Adding in more than one toggle button
Hi,
I am having problems when adding multiple toggles. I am unable to work out what its actually doing as occasionly when i click on toggle 2, its firing toggle 1 and the sometimes its doing it the other way around -clicking on toggle 1 will fire toggle 2.
Any help is much appreicated.
My code below:
//Adding flows to stage
var flow0:MovieClip = new mov_flow_0();
this.addChild(flow0);flow0.y = 235.80;
flow0.x = 142.50;var flow1:MovieClip = new mov_flow_1();
this.addChild(flow1);
flow1.y = 287;
flow1.x = 314.60;////////////////////////////////////////////
//Stop Flows
stopFlow();
//Setting up buttons
var totalButtons:int = 2;
var buttonArray:Array = new Array();
setUp();function setUp()
{
for (var i:int = 0; i<totalButtons; i++)
{
var mc = root["toggleBtn_" + i];
buttonArray = mc;
mc.buttonMode = true;
mc.addEventListener(MouseEvent.CLICK, btnClicked);
mc.btn.x = OFF_POSITION;
}
}function btnClicked(e:MouseEvent):void
{var id = e.target;
var index:int = getIndex(id,buttonArray);
onState = !onState;
var mc = root["toggleBtn_" +index];
var flowToUse = root["flow" + index];
trace ("mc: " + mc.name);
trace ("flowToUse: " + flowToUse);if(onState)
{
//mc.btn.x = ON_POSITION;
TweenMax.to(mc.btn, 0.5, {x:ON_POSITION});
flowToUse.flow.startFlow();}
else
{
//mc.btn.x = OFF_POSITION;
TweenMax.to(mc.btn, 0.5, {x:OFF_POSITION});
flowToUse.flow.stopFlow();}
}// function to search an array to find a given entry
function getIndex(id_to_find:Object,array_to_search:Array)
{
for (var i:int = 0; i<array_to_search.length;i++)
{
if (id_to_find == array_to_search)
{
return i;
break;
}
}
}function stopFlow()
{
flow0.flow.stopFlow();
flow1.flow.stopFlow();
}
