Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

ScriptUI Custom Events

People's Champ ,
May 02, 2013 May 02, 2013

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

TOPICS
Scripting
4.9K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Adobe Employee , May 03, 2013 May 03, 2013

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

...
Translate
Advisor ,
May 03, 2013 May 03, 2013

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
May 03, 2013 May 03, 2013

Thanks Vamitul for your remark

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
May 03, 2013 May 03, 2013

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....

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
May 03, 2013 May 03, 2013

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
May 06, 2013 May 06, 2013

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
May 07, 2013 May 07, 2013

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
May 07, 2013 May 07, 2013

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!!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jul 29, 2013 Jul 29, 2013

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Oct 03, 2015 Oct 03, 2015
LATEST

Amazing piece of vital information!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines