Closed notalentgeek closed 8 years ago
The best advice i can give is to use the userData
property on component. Its not an ideal solution though. Im sure it wouldnt be hugely complicated to get the macro that builds the event functions to add an additional Dynamic
param, but honestly i dont have time at the moment. :)
It is okay, your response is very fast tho :)). Honestly I have no clue on userData, neither on how it works.
In which file does field of onClick exist? I did search on Button.hx but I could not find anything named onClick. Perhaps I can hack a bit your code.
Its build by a macro at compile time, which basically creates a function onClick
which internally calls addEventListener
. The macro is being called here: https://github.com/ianharrigan/haxeui/blob/master/haxe/ui/toolkit/core/DisplayObject.hx#L17 and that macro itself is: https://github.com/ianharrigan/haxeui/blob/master/haxe/ui/toolkit/core/Macros.hx#L174.
For the userData its simply a Dynamic you can set to anything you want, but its related to a component (which is why it might not be ideal). Heres an example:
var button:Button = new Button();
button.userData = "this is user defined";
button.onClick = function(e:UIEvent) {
trace(e.component.userData);
}
Thanks Ian, I got my problem fixed by now!
How did you do it in the end? Just in case anyone else happens across this issue? Did you use .userData
?
Like you said in your example. What I have is a default button and 100 other buttons that have unique id. What I want to have is for the 100 other buttons to pass the id String to the button when one of them is clicked. Hence I passed the id of the button pressed into each of the 100 buttons. Here is the example code.
collectionGlobalObject.GetExhibitionObjectArray([i].GetMuseumUIObject().GetButtonObject().userData = collectionGlobalObject.GetExhibitionObjectArray()[i].GetMuseumUIObject().GetButtonObject().id;
Great! :)
buttonObject.onClick = function(_e:UIEvent){ trace("LALALA!"); }
The code above is the default way to call a function when you pressed a button. I want to add additional arguments, perhaps something like this.buttonObject.onClick = function(_e:UIEvent, ?_object:ObjectMuseum){ trace(_object.GetName()); }
But the code above returns an error like this.e : haxe.ui.toolkit.events.UIEvent -> ?_selectedMuseumObject : Null<ObjectMuseum> -> Void should be haxe.ui.toolkit.events.UIEvent -> Void
How to solve this problem? I want to add parameter on my button's onClick().