Array Attribute Referencing

  • Hi

    I'm trying to access an array programatically in order to populate attributes of a series of plugins. Yes, I've looked at the documentation and looked through the forum and seen some excellent examples. After going cross-eyed trying to figure out where the issue is, I still end up with a referencing problem.

    Pinsane's example
    variable in textfield / plugin is great but lacks the final dimension.

    It's the one that starts like this about halfway down the post (there are 166 lines of code, so it's not all here!) :
    <krpano language="dutch" >
    <preview type="grid(cube,16,16,512,0xCCCCCC,0x333333,0x999999);" details="16" />
    <phrase name="thumb1" >
    <language name="dutch" text="goedemorgen" />
    <language name="english" text="good morning" />
    </phrase>

    In the code snippet below which is taken from line 115 of the example, the array name and language are passed to locate the sub array. The individual attribute is given as ".text" - like this:

    onhover="showtext(get(phrase[get(name)].language[get(language)].text));"

    What I would like to do is to be able to pass the name of the attribute to be returned rather than hardcoding it. In the example above the ".text" would be passed to a function rather than being embedded.

    So much for the theory - I've tried referencing the ".text" part with %1 type arguments and with gets, txtadds and the like but I just get a null value returned. I"m going round in circles now...

    I would like to know if and how this can be done?

    Can it be done without a javascript snippet?

    Any light on this would be appreciated.

  • This is the method I use in a template I'm developing

    <!-- language configuration -->

    within the html I have this:

    Code
    <script>
    		var viewer = createPanoViewer({swf:"tour.swf", xml:"tour.xml", target:"pano", html5:"auto", passQueryParameters:true});
    		viewer.addVariable("LANGUAGE", 'en_gb');
    		viewer.addVariable("VERSION", '0.1');
    		viewer.embed();
    	</script>

    Now to access a language, I do this for example for the tooltips:

    Code
    <action name="show_tooltip">
    		<!-- if text isn't translated, just show the variable -->
    		if(languages.language[get(LANGUAGE)].%1 === null,
    			set(text, %1);
    			,
    			set(text, get(languages.language[get(LANGUAGE)].%1));
    		);
    		showtext(get(text), tooltip_style);
    	</action>

    the hotspot just has

    Code
    onhover="show_tooltip(close_popup)"

    I decided to keep the LANGUAGE variable outside krpano for now, because language will probally be detected server side. Perhaps I'll make the initial detection outside krpano through php, and then further handling be within krpano (for ex, a language dropdown menu).

    Downside of this system is that certain text's have to translated in the onloaded action or init action. For example you have a button called Home. This text has to be set before hand in a init function triggered by onnewpano, or the onloaded action of the textfield itself. I'd like to keep php code outside krpano as much as possible for easy editing. *thumbsup*

    btw also dutch?

Participate now!

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