I tried to use hypeDocument.customData and hypeDocument[“anyData”] , but I don’t see it working. Value after assigning any value comes undefined.
if ( ! hypeDocument.customData )
{
hypeDocument.customData = {} ;
hypeDocument.customData.myVar = 123 ;
}
alert( hypeDocument.customData.myVar) ;
if ( ! hypeDocument["myVar"] )
{
hypeDocument.["myVar"] = 123 ;
}
alert( hypeDocument["myVar"] ) ;
Alternatively I am right now using window.myVar , that is working. What am I doing wrong above ?
h_classen
(Hans-Gerd Claßen)
March 18, 2019, 5:20pm
2
your first example should work, but only applies if customData is not valid.
the second example makes use of the wrong quotes.
jonathan
(Jonathan Deutsch)
March 19, 2019, 11:19pm
3
It’d be good to post a zip of the .hype document if you can; in this case there might be an issue in when/how it is called more than the code itself (which at a glance looks okay).
I’d also recommend taking a glance at the developer tools console log of the browser and see if that reports anything.
DBear
March 20, 2019, 11:39am
4
@VishwasGagrani
I'm am assuming you are using the Beta version as if you are checking for ! hypeDocument.customData then the "myVar" key never gets assigned a value.
If you are using the non-Beta version then the customData object and associated key: value would get set and should alert "123".
This is what Hans has said. Also he mentions an error in your code which I will highlight
if ( ! hypeDocument.customData ) {
hypeDocument.customData = {} ;
hypeDocument.customData.myVar = 123 ;
} else {
hypeDocument.customData.myVar = 123 ;
}
alert( hypeDocument.customData.myVar) ;
if ( ! hypeDocument["myVar"] ) {
hypeDocument["myVar"] = 123 ; // no . before [
}
alert( hypeDocument["myVar"] ) ;
This code will work for both Beta and non-Beta. As Jonathan mentions though, an example would go along way to narrow down the exact cause as I'm guessing here as to what you've done.
@Jonathan
Maybe a better look i.e the . before the [
2 Likes