Copy link to clipboard
Copied
Hi all,
Is there any chance I can propagate custom events in ScriptUI ? I tried this sample in ESTK and it works fine. However I tried to run it in several CS apps and all my attempts raised errors. My intenttion is to create custom components that would throw events listened by the parent window. Am I asking too much ?
function test()
{
var w = new Window('dialog');
var btn = w.add('button');
w.addEventListener ('custom', tata);
btn.onClick = function()
{
w.close()
var e = new UIEvent('custom', true, true, w, null);
e.data= {test:"hello"};
w.dispatchEvent(e)
}
function tata(e)
{
alert(e.data.test);
}
w.show();
}
test();
Thanks for any hint/advice,
Loic
That whole ScriptUI event thing isn't meant to be extended. That it works in ESTK is likely an anomaly. With ScriptUI events, you can only make 1 of 3 types (keyboard events, mouse events, and...? uh...).
And you do that via ScriptUI.events.Event.createEvent() (or some syntax close to that - this is from memories in the CS4 timeframe).
But what you can do is write your own event system...
Something like this - of course you could write an event class, pass data, you name it.
See the attached file fo
...Copy link to clipboard
Copied
Hi loic!
I think i remember from an ancient failed experiment i did a long time ago that Indesign does not work with custom uiEvents. Don't know about the rest of the apps.
Copy link to clipboard
Copied
Thanks Vamitul for your remark ![]()
Copy link to clipboard
Copied
That whole ScriptUI event thing isn't meant to be extended. That it works in ESTK is likely an anomaly. With ScriptUI events, you can only make 1 of 3 types (keyboard events, mouse events, and...? uh...).
And you do that via ScriptUI.events.Event.createEvent() (or some syntax close to that - this is from memories in the CS4 timeframe).
But what you can do is write your own event system...
Something like this - of course you could write an event class, pass data, you name it.
See the attached file for one primitive way to do it....
Copy link to clipboard
Copied
Hi Bob,
Thank you so much. It's a very nice solution and indeed functional. Thanks again for this one.
For the record, I developed a scriptUI/SWF application for Bridge. It's ok in CS5.1 but it seems ScriptUI in Bridge CS6 doesn't support flash objects any longer ![]()
So I have to translate all the swf panel into pure ScriptUI. Your solution was the first stone I needed ![]()
Loic
Copy link to clipboard
Copied
Hi Loïc,
To my knowledge new UIEvent(…) works fine in InDesign (CS4/CS5/CS6) provided that you let the view parameter undefined.
So just try to replace:
var e = new UIEvent('custom', true, true, w, null);
by:
var e = new UIEvent('custom', true, true);
Note: Usually a custom UI event should be dispatched from a specific target—in your case: btn.dispatchEvent(e)—rather than from the top window. This way you can have multiple listeners that the event will hit during the bubbling phase:
// Propagation of a custom UI event (which bubbles)
// Tested in ID CS4/CS5/CS6
const EV_TYPE = 'MyCustomEventType';
var u,
w = new Window('dialog'),
p = w.add('panel'),
b = p.add('button',u,"Test"),
// ---
evHandler = function(ev)
{
alert( this + " is listening: " + ev.data );
},
myDispatcher = function(data)
{
var ev = new UIEvent(EV_TYPE, true, true);
ev.data = data;
this.dispatchEvent(ev);
};
w.addEventListener(EV_TYPE, evHandler);
p.addEventListener(EV_TYPE, evHandler);
b.onClick = function(){ myDispatcher.call(this, "Some data"); }
w.show();
@+
Marc
Copy link to clipboard
Copied
Hi Marc,
So I wasn' that far after all
Thanks a lot. It's also very helpful and functional indeed. I like the idea on getting stuck to the event bubbling process.
Best to all of you guys,
Loic
Copy link to clipboard
Copied
Hey Marc, thanks for teaching me something new to me!
If my recollection is correct, that's not supposed to work - but I'm very happy it does!!!
Copy link to clipboard
Copied
Hi,
I've happened to post something along these lines in the Photoshop forum - I've troubles with dispatchEvent() and a particular component.
If you're willing to spread your knowledge there too, the thread is this one: http://forums.adobe.com/message/5547956#5547956 ![]()
Thank you!
Davide
Copy link to clipboard
Copied
Amazing piece of vital information! ![]()
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more