Reputation: 15
I need to get my work increment and decrement variables mcnf5 and cnt5. The problem is that in this first pass code adds / subtracts 1, then 3, 5, etc ... I do not know exactly what causes it, but I need to impute variable when it clicks zdenca_volba1, zdenca_volba2 or zdenca_volba3 and with the delay I set. But the increment works just as it is not part of these functions. How to modify your code to work correctly delay and increment ?? Code is in actionscript3
function zdeClick5(event:MouseEvent):void{
if ((zdenca5ON == false)&&(mcnf5 > 0)) {
zdenca_prace5.visible = true;
zdenca_prace5.zdenca_volba1.addEventListener(MouseEvent.CLICK,z1Click5);
function z1Click5(event:MouseEvent):void{
zdenca_prace5.visible = false;
zdenca5.play();
zdenca5ON = true;
setTimeout(timedFunction51,3000);
function timedFunction51() {
mcnf5--;
mcnt5++;
mcnft5.text = mcnf5.toString();
mcntt5.text = mcnt5.toString();
zdenca5ON = false;
zdenca5.stop();}
}
zdenca_prace5.zdenca_volba2.addEventListener(MouseEvent.CLICK,z2Click5);
function z2Click5(event:MouseEvent):void{
zdenca_prace5.visible = false;
zdenca5.play();
zdenca5ON = true;
setTimeout(timedFunction52,10000);
function timedFunction52() {
mcnf5--;
mcnt5++;
mcnft5.text = mcnf5.toString();
mcntt5.text = mcnt5.toString();
zdenca5ON = false;
zdenca5.stop();}
}
zdenca_prace5.zdenca_volba3.addEventListener(MouseEvent.CLICK,z3Click5);
function z3Click5(event:MouseEvent):void{
zdenca_prace5.visible = false;
zdenca5.play();
zdenca5ON = true;
setTimeout(timedFunction53,5000);
function timedFunction53() {
mcnf5--;
mcnt5++;
mcnft5.text = mcnf5.toString();
mcntt5.text = mcnt5.toString();
zdenca5ON = false;
zdenca5.stop();}
}
Upvotes: 0
Views: 51
Reputation: 1716
so the problem here is each time you call zdeClick5()... you are adding ANOTHER set of listeners to all of the sub objects (i.e... denca_prace5.zdenca_volba2.addEventListener()). These listeners are all pointing to inline handlers (i.e.... function timedFunction53()). So, when you add duplicate listeners, as3 will ignore it. BUT, these aren't duplicates because each time you add one... it is pointing to a brand new inline function.
to fix this I would set up the event listeners and handlers outside of your function zdeClick5() (so they don't get added over and over again, and so they can point to one concrete function pointer for each listener).
Upvotes: 1