TL;DR: How can I observe a property that is inside a custom class?
I’m struggling with the following :
I’m creating a ToolbarButton class. I have a property called “Image” defined as :
<string ux:Property="Image" ux:Value="" />
Later, in my JS code I need to access that Image property to generate filenames for MultiDensityImageSource, but when I try to :
var baseName = "Assets/toolbar-" + self.Image + ".png";
The Image property is undefined (I was expecting an empty string). Also, it wouldn’t work if I changed the Image property externally, so, how can I watch for changes in the Image property?
(Also, sorry if it is a dumb question, I’m not an expert in the latest JS technologies)
Data-binding the ux:Property (like Gianko suggest) would be the right way to access a ux:Property from JS. Unfortunately this does not work in the current release, but it will in 0.9.8 (which will be released this week).
Hmm… Sorry to hijack this old thread now, but that actually doesn’t work for me :S (in v0.28.1)
I get ReferenceError: Text is not defined if I try using:
<Panel ux:Class="propertyTest">
<string ux:Property="Text" />
<JavaScript>
Text.value = "setting the property value from JS";
</JavaScript>
</Panel>
If I use a databinding it obviously works, and can be modified, but the binding is not initiated with the original property value I pass in.
Sorry, feel free to delete this and I’ll start a new thread if this is a bug report or more complex query. I was just curious if the initial example was still relevant to current Fuse.
<string ux:Property="SetAddress" />
<JavaScript>
function setDefaultAddress(args) {
this.SetAddress.Value = "setting the property value from JS";
}
module.exports = {
setDefaultAddress: setDefaultAddress
}
</JavaScript>
and get error on running setDefaultAddress function:
Error: TypeError: Cannot set property ‘value’ of undefined: Name: TypeError: Cannot set property ‘value’ of undefined
instead of posting on old threads, please make a new forum post with a complete, minimal reproduction that manifests the problem and can be copy-pasted and run.