Forum Discussion
WebObject and Storyline Variable
Hi!
I have a problem, I need to use a webobject with my project, but my webobject needs some informations. So, I put them in variables in Storyline and now my problem is how I can give them in the query string like this :
http://mywebobject.com/mysite.php?info1=VariableSL1&info2=VariableSL2
Do you have any idea?
Thank you very much!
- JasonJohnson2Community Member
Hey Steve, I'm very interested to see a working sample of that. Do you happen to have one you could share? Nothing too elaborate just something in working order. Thx!
- SteveFlowersCommunity Member
Hey Jason -
Can take a look tonight or this weekend!
- SinisterCommunity Member
For future reference for others, you can do to it like this for html5. In the slide where the webobject exists, create a new Javascript that starts at the beginning of the timeline. The script below is my interpretation of how to solve the OP's problem:
// Find and change the src part of the iframe (this will take the first webobject in the storyline, therefore [0]. If you want the second one, use [1], etc..
var iFrameElem = document.getElementsByClassName('item webobject')[0];var src = "http://mywebobject.com/mysite.php"
var player = GetPlayer();
var var1 = player.GetVar("info1");
var var2 = player.GetVar("info2");
// Add together the finished url with querystrings
var finishSrc = src + "?info1=" + var1 + "&info2=" + var2;
iFrameElem.setAttribute('src', finishSrc);- JacquiDyachCommunity Member
Thanks, Linus!
This worked, but I had to change the class from 'item webobject' to 'item webobject unhideable', as the containing div also uses the class 'item webobject'.
I was not initially clear, but the order of the web object [0] for first, [1] for second, etc. is specific to the slide, and not the entire project.
I am using Storyline 2, Update 11.
- KevinMcGloneCommunity Member
@Zsolt Olah: Thank you for the approach you provided.
I can get the variables out of Storyline which is great but when I try to set variables in storyline the function seems to breakdown ie it is not being fired.
Off course this is the functionality I need the most. I'm in the process of troubleshooting the issue.
Any suggestions as to why this isn't working going into Storyline? is there something in Storyline that I need to set to allow the variables to be written to?
- Jean-Guy-BoulayCommunity Member
deleted comment ... irrelevant
Hope it helps.
edit: I should point out, that I setup the setVariable in the story.html after the story.js loads.
function setVariable(vName,vValue)
{
var player=GetPlayer();
var myVar = player.SetVar(vName,vValue);
return myVar;
} - KevinMcGloneCommunity Member
Hi Jean-Guy,
Thanks for the reply. I will give it a try and report back here.
- KevinMcGloneCommunity Member
Changing 'Window' to 'Parent' in the Web object breaks the Web Object and there would be a high development overhead to re-develop in my case.
The strange thing is 'parent.getVariable' works ie it gets the variable from Storyline.
I might try getting the variable from within Storyline. - Jean-Guy-BoulayCommunity Member
Is your webobject code in the body or the head? I placed mine in the body. it's been a few months ago, but I recall I was getting no communication when I had the code in the Head of the webobject. I also added an eventlistener to ensure that the vars updated in the webobject before executing setVariable.
- KevinMcGloneCommunity Member
Hi Jean,
Thanks again for coming back I appreciate your help.
I have found my issue with the help of a fresh set of eyes.
It was a Case issue in the function I was using for setting.
The 's' in 'SetVar' is lower case in Zsolts original post where I copied the function from.
Everything works as it should now.
Moral of the story, Always verify syntax and case in all code. :-)
Thanks again and hopefully this helps others.
Happy Friday! :->
Correct working syntax functions copied directly from my working JS file below:
function getVariable(vName){
var player=GetPlayer();
var myVar = player.GetVar(vName);
return myVar;
}function setVariable(vName,vValue)
{
var player=GetPlayer();
var myVar = player.SetVar(vName,vValue);
return myVar;
} - ZsoltOlahSuper Hero
I just saw this chain, not sure why I wasn't getting notifications when someone replied... And it's been there for a while but if someone is still interested, I just had two sessions on using a game engine (Construct 2) with Storyline at the ATD TechKnowledge conference.
I put together an interactive guide book how to build a game with source files.
You may not work with a game engine but the output of the game engine is HTML5. Check out the section on Integration with Storyline. There's an example you can download with explanation how it works under: Playbook 4 Integration with Storyline 2 -> Integration package
http://rabbitoreg.com/atd-tk-integration-package/
My original blog example: http://rabbitoreg.com/2015/03/23/c2s2/
And here's one implementation to see it in action: http://rabbitoreg.com/2015/06/11/when-i-ruled-the-world/
- RichardHill-4f3Community Member
Hey Zsolt, could you relink the integration package if you still have it? The link seems dead. : (