Sie sind nicht angemeldet.

1

Dienstag, 17. April 2018, 10:02

Image resize depending on number of clicks

Hi everyone,

I was wondering if i could resize the image depending on what click number it is on. For example, I want to declare a variable called count = 0 in the beginning of my scene. Everytime the image is clicked, that count variable will increment. If count is odd, then make the image smaller, but if count is even, then make the image the original size. I was wondering if i would have to make a javascript function within my XMl file to do this; would I have to use an <action> and make the type "Javascript" ? Thank you.

2

Mittwoch, 18. April 2018, 10:50

Hi,

here a small code snippet for counting the clicks and checking for odd or even:

Quellcode

1
2
3
4
5
6
7
8
9
10
11
<events name="myevents" keep="true" onclick="myonclickaction()" /> 
<action name="myonclickaction">
    if(clickcounter === null, set(clickcounter,0));
    inc(clickcounter);
    trace('clicks=',clickcounter);
    if( (clickcounter BAND 1) == 1, 
        trace('- odd number of clicks');
      , 
        trace('- even number of clicks');
    );
</action>


Best regards,
Klaus

3

Mittwoch, 18. April 2018, 11:48

Hi,

here a small code snippet for counting the clicks and checking for odd or even:

Quellcode

1
2
3
4
5
6
7
8
    if(clickcounter === null, set(clickcounter,0));
    inc(clickcounter);
    trace('clicks=',clickcounter);
    if( (clickcounter BAND 1) == 1, 
        trace('- odd number of clicks');
      , 
        trace('- even number of clicks');
    );


Best regards,
Klaus
Thanks Klaus! Works flawlessly