How to set default button and global variables?

Two questions:

1. Total 3 menus with several buttons in each of them. how can I return to the correct menu with correct button focused after playing through each clip

2. If I have several .js file, where should I set the global variables that could be shared among all .js during disc playback

Many thx!



Answer this question

How to set default button and global variables?

  • Joseph Stalin

    Could be a Sonic bug (does it work on HDiSim )

    Also remember that you MUST set the XPath variable in your markupLoadedHandler, otherwise the markup engine will crash on all players due to an undeclared variable.



  • upgraders

    Easiest thing to do is to remember who has the focus when you leave one menu, and store it in a variable. Then when you load a page, use a simple animation to set the focus correctly:

    // When leaving the page:
    var focusedButton = GetFocusedButton();
    if (focusedButton != null)
    resumeFocusId = focusedButton.core.id;

    // When loading the page (ie, setMarkupLoadedHandler)
    document.setXPathVariable("ResumeFocus", String(resumeFocusId));

    // Helper function
    function GetFocusedButton()
    {
    try {
    var elementList = document.evaluateXPath("//button[state:focused()]", document);
    if (elementList != null && elementList.length > 0)
    return elementList[0];
    } catch(ex) { }

    return null;
    }

    <!-- In the markup -->
    <cue select="id($ResumeFocus)" dur="0.5s">
    <set state:focused="true" />
    </cue>

    Script globals cannot be shared across applications; to do that you need either use GPRMs or have a PlaylistApplication that stores information and then uses events to coordinate back and forth with the other applications.



  • David_JS

    Thank you. I followed your instruction but always having error on

    <cue select="id($ResumeFocus)" dur="0.5s">
    <set state:focused="true" />
    </cue>

    The error message on Sonic debug utility is "SetNode: Trying to <set> with an empty default node set."

    I couldn't see anything wrong from the code.


  • How to set default button and global variables?