Not able to store custom data with hypedocument object or hypedocument.customData

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 ?

your first example should work, but only applies if customData is not valid.
the second example makes use of the wrong quotes.

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.

@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 :stuck_out_tongue: i.e the . before the [ :smiley:

2 Likes