Question

Looking at the javafx tutorials and samples, bindings are always made during varibale declarations:

def y = bind x;

or

def address = Address {
  street: bind myStreet;
};

But what do I do, if I have an exisiting object - and hence don't declare it - and want to bind one of its attributes. In my case I load a SVGPath with the FXDLoader and then want to bind SVGPath.visible to a variable. How can I achieve this?

var data = true;
var fxdContent = FXDLoader.load("{__DIR__}plan.fxz");
var sc = fxdContent.lookup("SC0013") as SVGPath;
sc.visible = bind data; //That doesn't work
Was it helpful?

Solution

You can use a replace trigger instead e.g.

var fxdContent = FXDLoader.load("{__DIR__}plan.fxz");
var sc = fxdContent.lookup("SC0013") as SVGPath;
var data = true on replace {
    sc.visible = data;
}

You might also be able to do:

def data = bind sc.visible with inverse;

This would give you bidirectional updates between the two variables. According to the language specification, you can't use "bind" anywhere else.

OTHER TIPS

Yes, you can bind a variable only when you are declaring it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top