hotspot.action() vs callwith(hotspot, action)?

  • Hello,

    I have mutiple hotspots with custom action.

    ex.

    <hotspot name="hs1" custom_action=".." />

    <hotspot name="hs2" custom_action=".." />

    <hotspot name="hs3" custom_action=".." />

    ...


    And I want to call these custom_action inside an action.

    <action name="action1">

            for(set(i,0), i LT hotspot.count, inc(i), 
                   hotspot[get(i)].custom_action();
               );
           );

    </action> 


    However in this case, only one hotspot's custom_action is called.

    When I change the code from

    hotspot[get(i)].custom_action();

    to

    callwith(hotspot[get(i)], custom_action);

    It works fine -> all hotspots' custom_action are called.


    Can somebody explain why?

    Maybe I should always use callwith() function instead of hotspot.action() style?


    Cheers,

    Hyung

  • Hi,

    I have tested your example now this way:

    Code
    <hotspot name="hs1" custom_action="trace(1)" />
    <hotspot name="hs2" custom_action="trace(2)" />
    <hotspot name="hs3" custom_action="trace(3)" />
            
    <action autorun="true">
      for(set(i,0), i LT hotspot.count, inc(i), 
        hotspot[get(i)].custom_action();
      );
    </action>

    And its works correctly, it traces 1,2,3.

    One thing to consider - the 'i' gets modified (increased) in the loop, so when your code might do the get(i) layer or delayed, it would result in a different value! Maybe that's the actual problem in your original code.

    Best regards,
    Klaus

  • Hello Klaus,

    Sorry I think I made my code was too short.

    Please refer to the code below (which is more similar to my actual code)

    I have a style and several hotspots which use this style:

        <style name="polygonal_hs"
            blink_on="tween(fillalpha, 1, 0.5,, blink_off());"
            blink_off="tween(fillalpha, 0.3, 0.5,, blink_on());"
            fillcolor="0xffff00" fillalpha="0.30"
            bordercolor="0xffff00" borderalpha="0.80"
            onover="stop_blink2();"
            onout="restart_blink2();"
            onloaded="blink_on();"
            stop_animation="stoptween(fillalpha);"
        />

        <hotspot name="h1_t" style="polygonal_hs" >
            <point ath="-72.9589" atv="-30.4572" />
            <point ath="-70.4091" atv="-27.2998" />
            <point ath="-67.2064" atv="-31.3229" />
            <point ath="-59.0580" atv="-16.6194" />
            <point ath="-55.6416" atv="-18.9404" />
            <point ath="-64.4720" atv="-33.8924" />
            <point ath="-59.5064" atv="-37.4353" />
    -        <point ath="-63.7152" atv="-42.0385" />
        </hotspot>

        <hotspot name="h2_e" style="polygonal_hs">
            <point ath="-56.6233" atv="-37.5551" />
            <point ath="-48.2821" atv="-21.7764" />
            <point ath="-40.4096" atv="-22.5966" />
            <point ath="-40.1212" atv="-27.2638" />
            <point ath="-47.2280" atv="-26.8896" />
            <point ath="-48.2008" atv="-29.8786" />
            <point ath="-45.2454" atv="-31.7670" />
            <point ath="-47.3317" atv="-35.2486" />
            <point ath="-49.3959" atv="-33.4768" />
            <point ath="-51.9742" atv="-36.4485" />
            <point ath="-48.7434" atv="-39.6989" />
            <point ath="-52.2168" atv="-43.0692" />
        </hotspot>

        <hotspot name="h3_x" style="polygonal_hs">
            <point ath="-49.2304" atv="-45.3128" />
            <point ath="-37.9226" atv="-38.2654" />
            <point ath="-37.0980" atv="-22.9855" />
            <point ath="-31.1866" atv="-24.5562" />
            <point ath="-31.6545" atv="-35.9112" />
            <point ath="-21.0987" atv="-26.9081" />
            <point ath="-13.3231" atv="-28.9798" />
            <point ath="-29.6066" atv="-41.6111" />
            <point ath="-28.5883" atv="-56.1656" />
            <point ath="-36.9412" atv="-52.3019" />
            <point ath="-36.4842" atv="-43.3404" />
            <point ath="-45.5119" atv="-48.8976" />
        </hotspot>


    When I mouse over on any of the hotspots, I want all hotspots' blink tween to be stopped and then start again when I mouse out.

    First I have tried this code which works only with one single hotspot instead of all hotspots.

        <action name="stop_blink1">
            for(set(i,0), i LT hotspot.count, inc(i), 
                if(hotspot[get(i)].style == "polygonal_hs",                
    hotspot[get(i)].stop_animation();
                );            
            );       
        </action>
        <action name="restart_blink1">
            for(set(i,0), i LT hotspot.count, inc(i), 
                if(hotspot[get(i)].style == "polygonal_hs",                
    hotspot[get(i)].blink_on();
                );            
            );       
        </action>    


    And when I use callwith function instead of hotspot.action() style, everything works fine.

        <action name="stop_blink2">
            for(set(i,0), i LT hotspot.count, inc(i), 
                if(hotspot[get(i)].style == "polygonal_hs",                
    callwith(hotspot[get(i)], stop_animation);
                );            
            );       
        </action>
        <action name="restart_blink2">
            for(set(i,0), i LT hotspot.count, inc(i), 
                if(hotspot[get(i)].style == "polygonal_hs",                
    callwith(hotspot[get(i)], blink_on);
                );            
            );       
        </action>


    Can you exaplain the difference?

    Maybe I should try to use callwith function whenever possible? (instead of hotspot.action())


    Cheers,

    Hyung

    Edited once, last by hyung (October 10, 2024 at 7:56 AM).

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!