Sie sind nicht angemeldet.

1

Montag, 12. Februar 2018, 09:14

javacript caller and resolve?

hi klaus,

javascript in xml actions are described in the docs here...
https://krpano.com/docu/xml/#action.js

but how do you get caller and resolve if you define a krpano action in js itself?
ie. in a js plugin

Quellcode

1
2
3
4
	krpano.actions.test = function(s){
		krpano.trace(1,"test:"+s);
		// how to get caller?
	}


best, index

2

Dienstag, 13. Februar 2018, 21:05

and another one...
how would i translate something like that into pure js for a plugin?

Quellcode

1
2
3
    asyncloop(caller.pressed,
        ....
    );


i guess i could use krpano.actions.asyncloop()
but this function expects action code, not js code, right?
is there a way to use such actions like asyncloop with js code?

index

3

Dienstag, 13. Februar 2018, 21:39

Hi,

but how do you get caller and resolve if you define a krpano action in js itself?
That's currently no documented, but there is a 'krpano.actions.actioncaller' variable which points to the caller object (when there is one, otherwise it is null).

A 'resolve' function is not available in that context, but here a simple get() could be used instead - when get() returns null use the name of the variable as value.


is there a way to use such actions like asyncloop with js code?
Sorry, that works only with actions code.
What you could do is either using jscall() in the loop code or adding a custom JS function and calling that in the loop code.

Best regards,
Klaus

4

Mittwoch, 14. Februar 2018, 10:20

thanks klaus,

all clear...

but i have another one...

Quellcode

1
screentolayer(get(caller.name), mouse.stagex, mouse.stagey, currentx, currenty);

i guess setting js variables directly doesnt work in such cases, right?

so this translates to:

Quellcode

1
2
krpano.actions.screentolayer(krpano.actions.actioncaller.name, krpano.mouse.stagex, krpano.mouse.stagey, 'currentx', 'currenty');
krpano.trace(0, krpano.currentx + '/' +  krpano.currenty);

is that correct?


plus one more...
in xml action script you check an unset variable with

Quellcode

1
if(variable === null, ... );

but a direct use of this in js does not work because in javascript null !== undefined
is it correct that the above line translates to...

Quellcode

1
if(variable === undefined || variable === null) { ...  }

?

best, index

Dieser Beitrag wurde bereits 5 mal editiert, zuletzt von »indexofrefraction« (14. Februar 2018, 21:05)


Ähnliche Themen