How should I handle multiple event listeners in my HTML5 extension?

Hi all

I want to hear to make events ("Mk") and to reproduce ("Dplc"), each using a different Manager events. Currently, two event handlers are triggered when an event is received.

The relevant javascript code is:

var make_e = new CSEvent(
  'com.adobe.PhotoshopRegisterEvent',
  'APPLICATION',
  csInterface.getApplicationID(),
  csInterface.getExtensionID()
);
make_e.data = 1298866208; // stringIDToTypeID('make')
csInterface.dispatchEvent(make_e);
csInterface.addEventListener( 'PhotoshopCallback', make_callback );

var dplc_e = new CSEvent(
  'com.adobe.PhotoshopRegisterEvent',
  'APPLICATION',
  csInterface.getApplicationID(),
  csInterface.getExtensionID()
);
dplc_e.data = 1148218467; // stringIDToTypeID('duplicate')
csInterface.dispatchEvent(dplc_e);
csInterface.addEventListener( 'PhotoshopCallback', dplc_callback );


function make_callback(e){ console.log('make'); }
function make_callback(e){ console.log('duplicate'); }

When an event is received the console saves the output of these two managers. In the example I first created a new layer then duplicated a layer below.

do c_LayerPanelSection.js:90

Double c_LayerPanelSection.js:94

do c_LayerPanelSection.js:90

Double c_LayerPanelSection.js:94

Answering my own question again

I wrote this class based on a similar com.adobe.webpa.crema.

You can use it by recording events with eventDelegate.addEventListener

var PhotoshopCallback = function(e) {
  var callback;
  try {
  if( e.data ) {
  //  + before variable uses numerical representation of the variable
  eventDelegate.invoke( +e.data.split(',')[0], e );
  }
  } catch(err) {
  console.log( 'PhotoshopCallback Error : ' + err );
  }
}

function EventDelegate() {
  this._events = [];
}

EventDelegate.prototype.invoke = function( eventType, e ) {
  var callback = this._events[eventType];
  if( callback ) {
  callback(e);
  }
}

EventDelegate.prototype.__registerPSEvent = function( typeID, clear ) {

  var eventEnding = null;
  if( clear ) {
  console.log( 'Unregistering ' + typeID );
  eventEnding = 'PhotoshopUnRegisterEvent';
  csInterface.removeEventListener("PhotoshopCallback", PhotoshopCallback);
  } else {
  console.log( 'Registering ' + typeID );
  eventEnding = 'PhotoshopRegisterEvent';
  csInterface.addEventListener("PhotoshopCallback", PhotoshopCallback);
  }

    var e = new CSEvent(
    "com.adobe." + eventEnding,
    "APPLICATION",
    csInterface.getApplicationID(),
    csInterface.getExtensionID()
    );
    // e.data = Object.keys(this._events).join(", ");
    e.data = typeID;
    csInterface.dispatchEvent(e);
}

EventDelegate.prototype.addEventListener = function( typeStrings, callback ) {
  csInterface.evalScript( "s2t('"+typeStrings+"')", function(r){
  this._events[+r.split(',')[0]] = callback;
  this.__registerPSEvent( r, true );
  this.__registerPSEvent( r );
  }.bind(this) );
}

EventDelegate.prototype.removeEventListener = function( typeStrings, callback ) {
  csInterface.evalScript( "s2t('"+typeStrings+"')", function(r){
  this._events[+r.split(',')[0]] = null;
  }.bind(this) );
}

var eventDelegate = new EventDelegate();
// module.exports = eventDelegate;

Tags: Photoshop

Similar Questions

  • How to remove base class event listeners

    Guys, I have a base class (he is a clip) in which I added event listeners:

    addEventListener (MouseEvent.MOUSE_OVER, mouseOverHandler);

    OK, it works and everything is beautiful.

    But I have a subclass that clip in class 'regular ': as3

    class DifferentClass extends MyMovieClip

    {

    }

    you get the gist.

    Now, I want in my DifferentClass also have the MOUSE_OVER event, but without never to raise the base class event.

    No one knows how to do?

    Thank you.

    override protected function mouseOverHandler(e:MouseEvent):void {}

    do not call super. Instead, do your own thing custom

    }

    No need to call getQualifiedClassName. This is what has protected methods are for!

    Note You can also listen to a higher priority and the preventImmediatePropogation() on the event if for any reason any substitution does not work for you.

  • How to add programmatically itemclick event listeners

    I have a horizontal list I need to assign a method to the ItemClick event

    in MXML I can do it with the following code,

    < mx:HorizontalList id = "hlst1" itemClick = "ClickHandler ()" / > "

    But in my application, I can't use MXML as horizontal lists are generated dynamically,

    in this case how can I assign an ItemClick event handler?

    Hello

    Try this

    private function test (): void
    {
    var hl:HorizontalList = new HorizontalList();
    hl.addEventListener (ListEvent.ITEM_CLICK, itemClickHandler);
    }
               
    private void itemClickHandler(event:ListEvent):void
    {
                   
    }

  • How should I handle sync library in laptops? (Cloud creative)

    Hello

    I've been a casual user of LR for a few years (version 4 I think that I use) but just take a subscription of the CC.

    I just need a little help to understand the best way to structure my library.

    Current configuration:

    • I have a portable 'main' (mobile desktop replacement, rest at home) and a surface pro 3 (come with me) and you have now installed LR CC on both machines.

    • My actual images are synchronized on both computers through my SIN - and happy to keep it that way.

    • My library (and associated folders previews) are also sync through through my NAS devices.

    This configuration "works", but it seems the right way to keep my library in sync - especially since the previews are constantly hammering the NAS (everything syncs quasi real)

    Is there a more effective way, I should be approaching this? for example, should I keep the library itself in sync, but exclude the overview files - or can CC handle all this for me, allowing me to keep the data of the library in non-sync had records on each device? My hypothesis is that it can (and was part of the reason why I took the subscription of the CC), I'm just there have not seen in action yet!

    Thank you!

    Hello

    Greetings!

    The architecture you are using is perfectly fine.

    Collection of sync Lightroom CC with mobile Lightroom, you don't use not.

    If you do not have to make changes to your settings.

    Concerning

    Jitendra

  • How the Ombudsman handles multiple responses

    I have a mediator who sent the same message to two BPEL process. When the two return process, they send back different answers. What the itinerary of the mediator response will return to the original caller?

    I don't see how we can combine the, because they can return at different times, and they can be different. If anyone knows how to combine them, it would be great.

    If it can not be combined, is it time based, the first reaction of BPEL is used, or the last answer?

    Thank you!

    "22 understanding Message Exchange Patterns of a mediator" described developer guide how input is mapped to the output for all models.

  • Another that holding down the power button, then by restarting, how should I manage my end 2009 27 "iMac when he crashes on the first blank white screen and won't start?

    Another holding down the power button, then by restarting, how should I handle turn on my end 2009 27 "iMac when he crashes on the first blank white screen and won't start?

    Combinations of keys start for Mac - Apple Support

  • Question of optimization: 1 handler for multiple events or 1 Manager by the event?

    Something I can't decide, simply because I'm not sure what would be most effective.

    Example: I have a few menus, each with a handful of icons click on (say a total of 10 objects that can be clicked on).

    Would it not be better to have 1 stage.addEventListener (MouseEvent.MOUSE_DOWN, clickHandler); with 10 if (e.target.name == "nameX") who is called on each click.

    Or would it be better to have 10 separate objectX.addEventListener (MouseEvent.MOUSE_DOWN, clickHandlerX); for each menu item that can be clicked?

    I suppose my confusion comes from not knowing what a listener does exactly, it uses all the resources I look for an event?

    (added)

    After typing all this, a good comparison would be closer to an event listener is nothing else than a way to call a function and is not otherwise using resources?

    My question is still, but I'm leaning towards several Auditors and managers.

    (add 2)

    Sorry my brain blurs, I'm not good at explaining things.  I think it's a little clearer.

    For 1 menu I 1 this.addEventListener, and in the Manager, he has several if (menu_itemX.name == "nameX").
    It is better to have 1 eventListener in this situation, or would it be better to have several menu_itemX.addEventListener and managers separated for each action?

    (follow-up question)

    I did addEventListener when the menu opens and removeEventListener when the menu closes.  If the event listeners do not use 'no' resources unless their event fires is a bad practice for simple click and mouseover events mouseout/mouseouthandler()?  Should I just leave the event listeners here all the time?

    (sample code)

    If this makes it more clear which of these would work better?

    Version 1:

    this.menu1.addEventListener(MouseEvent.MOUSE_DOWN, clickHandler1);
    this.menu2.addEventListener(MouseEvent.MOUSE_DOWN, clickHandler2);
    this.menu3.addEventListener(MouseEvent.MOUSE_DOWN, clickHandler3);
    this.menu4.addEventListener(MouseEvent.MOUSE_DOWN, clickHandler4);
    this.menu5.addEventListener(MouseEvent.MOUSE_DOWN, clickHandler5);
    
    function clickHandler1(e:Event):void{}
    function clickHandler2(e:Event):void{}
    function clickHandler3(e:Event):void{}
    function clickHandler4(e:Event):void{}
    function clickHandler5(e:Event):void{}
    

    version 2:

    this.addEventListener(MouseEvent.MOUSE_DOWN, clickHandler);
    
    function clickhandler(e:Event):void{
    if(e.target.name == "menu1"){}
    else if(e.target.name == "menu2"){}
    else if(e.target.name == "menu3"){}
    else if(e.target.name == "menu4"){}
    else if(e.target.name == "menu5"){}
    }
    
    

    the leave it alone as long as your menu works as expected while adding them.

    leaving the listener takes memory.  removing it frees this memory.

    but free up memory and adding memory uses system resources, especially when free memory flash gc.  It is unnecessary to repeatedly the gc objects that will be added to memory later.

  • Global events and global event listeners does not work!

    I don't know who to ask if I have questions about knowledge base articles so I'll post here.

    I want to push the alert as how dialog box integrated calendar alerts to users. I understand that I need to use the globalevents and listeners, so I studied it in the knowledge base article below:

    http://supportforums.BlackBerry.com/T5/Java-development/global-events-and-global-event-listeners/TA-...

    However, when I run the code, it does nothing. The way it is set up, it should display messages ("received event, sending accused of receipt and acknowledgement received"), but nothing happens on my Simulator, once I have 'fire' of the global event. Help, please!

    No problem. We were all there at one point.

    Each of these files has a main method that is your entry point to the application. Since everyone has one, they all have two need to have their own projects.

    For example, to create a new project for each of these files in Eclipse (or JDE; Eclipse preferred) and drop the code in., and then run the two projects on the Simulator.

    Once both applications on the sim card, you can then view the interaction between the two applications.

  • How to intercept the Message event opened on existing messages Inbox

    I asked in this thread for a way to override the event open Message in the Inbox so that I could see a message personalized with my own Viewer.

    Doug suggested that I create a folder and message listeners to intercept events that interest me.

    It works partially. The FolderListener can detect new messages coming, but he does nothing with the existing messages, so, in my app initialization, I loop over the existing messages and look for those to whom I want to fix a messageListener.

    I reinforced with the code and see that the headphones are fervent. But the modified (event MessageEvent) method never fires on existing messages when I opened the. It fires only on messages received recently.

    How can I catch the event message open for existing messages?

    Also, when I catch the event on new messages, it opens my custom desktop, but when I go back to the list of messages, he had also opened the message with the default mail Viewer. Is there an equivalent to CONSUME_CLICK a button to say that if I got trapped in the event to just make my personalized treatment and not the default behavior?

    Thank you!

    Dave

    What I do is I store the operating screen and close it after the event handling:

    public void open(MessageEvent messageEvent)
    {
        if (messageEvent.getMessageChangeType() == MessageEvent.OPENED)
        {
            final Screen mailScreen = UiApplication.getUiApplication().getActiveScreen();
    
            // DO YOUR THING WITH THE SCREEN
    
            String className = mailScreen.getClass().toString();
    
            /*
             * Only close the active screen if it's the EmailViewerScreen.
             *
             * Note: This is undocumented so I'm not sure whether this will always work.
             */
            if (className.endsWith(".EmailViewerScreen"))
            {
                UiApplication.getUiApplication().invokeLater(new Runnable()
                {
                    public void run()
                    {
                        try {
                            mailScreen.close();
                        }
                        catch(Throwable t) {
                            // log error
                        }
                    }
                });
            }
            else {
                // log that Classname is not-a EmailViewerScreen
            }
        }
    }
    
  • Event listeners generate errors while the modal windows are shown.

    Hi all

    I have an interface in ui script that relies on headphones for events initialized as follows:

    var button = palette.add ('image', rect);
    button.onDraw = buttonDraw;
    button.addEventListener ('mouseover', onMouse, false);
    button.addEventListener (onMouse, 'mouseout/mouseouthandler()', false);
    button.addEventListener ("mousedown", onMouse, false);
    button.addEventListener ("mouseup", onMouse, false ");

    I need these events if I change images (false buttons) when the user moves the mouse over them or click on one of them. Everything works as it should, until I decided to give something back. Although made in After Effects, a window or something is open somewhere and it makes all the unnecessary scripts, they do not meet the entry to any user, and it is very good for me. It works the same for all of the scripts that I tested.

    The real problem is with event listeners. The scripts that use will generate them a substantive error if no listener is enabled. And when rendering finished, AE will display a pop-up allowing you to know these errors. Also the interface script stops turning completely until you close open again.

    The error message is:

    "Cannot run a script so that a modal dialog box is waiting for answer".

    I thought to replace all the headphones by the other type of reminder like 'onClick', but it seems that there is no work around to "mouseover" or "mouseout/mouseouthandler()".

    It is a real problem for my user interface, as if the user has my Panel anchored somewhere in the interface and simply move the mouse on one of the buttons, it will end with the error at the end to make it. There are also I can't do anything to avoid the listeners to run, because once the script is loaded, we lose all control of what goes with it, no way to temporarily remove listeners.

    Any ideas on how to solve this problem?

    I found a solution to my problem.

    I had to remove the listenerer of the 'mouseout/mouseouthandler()' event when my custom onDraw function has been executed as a result of the actual mouse out (in other words drawing my picture in the iddle version). Then I just reinstall the event "mouseout/mouseouthandler()" at the "mouseover" event is triggered.

    I also tried to remove the "mouseout/mouseouthandler()" in my function onMouseOut listener, but it did not work very well, the only way was to remove it in the custom onDraw.

    Another thing, I discovered, is that the "mouseout/mouseouthandler()" event is actually fired 2 times... every time! That's probably a bug.

    I'll mark this as answered even if it's more as a workaround that dirty a real difficulty. I think it's a bug in After Effects (at least).

    UQg about your question, do you have a thread for it? Otherwise, you need to create one, I also have this problem and I'll look into it.

  • Make several event listeners to perform the same function

    I have a block of code. I have attached two different event listeners, one on the scene and the other to a button. I want him out when the event triggers, the event handler should run. Look at the code. Thank you.

    Try this...

  • Can I detect and handle an event already within a structure of the event?

    I have a VI that would do what I want, if I could detect and handle an event of second mouse click while I'm already handling a previous event (selection from popup menu).

    I hope that the picture is clear, but in words what I want is the following: I have first right-click on a chart and select a context menu item, which specifies a graphic manipulation of properties.  Often, this manipulation requires clicking on a second graph to get a reference (for example if I want to copy some of the properties of the first chart on the chart of the target).  It is, it means I'm trying to detect a second event already within a structure of the event.

    I think I could do with a state machine and some registers at offset, and if it's the easiest way, I'll do it.  I would be interested to know whether, if there is a way to detect and manage events 'nested' as I suggested.

    Thank you!

    Your code is not really that complicated.

    Yet, the problem is that confuse you it upward with the main state machine. I would use it in a small parallel loop that only manages events associated with the menu shortcuts. All this should be able to run in parallel in any event, even if the main loop updates the data in the chart at the same time, for example.

    I don't like the dialog box, it hampers the flow of work, but if you use it, use two button dialog so that the user can also cancel if necessary. Instead of the dialog box, you should just temporarily move the cursor on. I also do little to check before operating on the second graph of reason and give a time limit for the second operation.

    Here is a quick project to a more atomic shortcuts Manager. Modify if needed. There are probably bugs.

  • The latest XP update has been installed. Machine will not start now. How should I do?

    Original title: Windows XP update killed my PC
    April 13, 2011, the latest XP update has been installed.  Machine will not start now.  How should I do?

    Thank you

    Them

    From the F8 Advanced Boot Options menu, were you unable to choose:

    Disable the automatic restart in the event of system failure

    Your system sounds like it restarts to determine what he complains and then someone can help you to repair.

    This is why there is a disable automatic restart on system failure option...

    There is another option in the menu F8 Advance Startup Options:

    Last good Configuration known (your most recent settings that worked)

    I do not think that this will help you, but you can at least say you tried it if someone suggests.

    MS products generally work as expected, but may not perform as desired or expected.  You can push that dog and make good the bark.

  • How should I pursue a model of After Effects in Flash?

    Hello. I am very new to flash and basically need to learn how to create banner ads. Because I wanted a little more dynamic animations in my banner I created a comp in After effects. I want to use this model as my base in flash and then add buttons for mouse events in flash.

    However, I am not able to export my computer a friendly file Flash (SWF, FLV)

    And when I import a video all the that get is a picture of the scenario.

    How should I go about this.

    Thank you

    Flash Pro CC - général to After Effects>

    I wouild publish a mp4 and import that uses the default settings.  You can then use the cuepoints in your video to add items/code/etc.

    After that the effects experts may have better ideas.

  • How can I select multiple cells in tableview with javafx only with the mouse?

    I have an application with a tableview in javafx and I want to select more than one cell only with the mouse (something like the selection that exists in excel). I tried with setOnMouseDragged but I cant'n do something because the selection only returns the cell from which the selection started. Can someone help me?

    For events of the mouse to be propagated to other than the node in which nodes the drag started, you must activate a 'full-drag-release press gesture' by calling startFullDrag (...) on the original node. (For more details, see the Javadocs MouseEvent and MouseDragEvent .) You can register for MouseDragEvents on cells of the table in order to receive and process these events.

    Here's a simple example: the user interface is not supposed to be perfect, but it will give you the idea.

    import java.util.Arrays;
    
    import javafx.application.Application;
    import javafx.beans.property.SimpleStringProperty;
    import javafx.collections.FXCollections;
    import javafx.collections.ObservableList;
    import javafx.event.EventHandler;
    import javafx.geometry.Insets;
    import javafx.scene.Group;
    import javafx.scene.Scene;
    import javafx.scene.control.Label;
    import javafx.scene.control.SelectionMode;
    import javafx.scene.control.TableCell;
    import javafx.scene.control.TableColumn;
    import javafx.scene.control.TableView;
    import javafx.scene.control.cell.PropertyValueFactory;
    import javafx.scene.input.MouseDragEvent;
    import javafx.scene.input.MouseEvent;
    import javafx.scene.layout.VBox;
    import javafx.scene.text.Font;
    import javafx.stage.Stage;
    import javafx.util.Callback;
    
    public class DragSelectionTable extends Application {
    
        private TableView table = new TableView();
        private final ObservableList data =
            FXCollections.observableArrayList(
                new Person("Jacob", "Smith", "[email protected]"),
                new Person("Isabella", "Johnson", "[email protected]"),
                new Person("Ethan", "Williams", "[email protected]"),
                new Person("Emma", "Jones", "[email protected]"),
                new Person("Michael", "Brown", "[email protected]")
            );
    
        public static void main(String[] args) {
            launch(args);
        }
    
        @Override
        public void start(Stage stage) {
            Scene scene = new Scene(new Group());
            stage.setTitle("Table View Sample");
            stage.setWidth(450);
            stage.setHeight(500);
    
            final Label label = new Label("Address Book");
            label.setFont(new Font("Arial", 20));
    
            table.setEditable(true);
    
            TableColumn firstNameCol = new TableColumn<>("First Name");
            firstNameCol.setMinWidth(100);
            firstNameCol.setCellValueFactory(
                    new PropertyValueFactory("firstName"));
    
            TableColumn lastNameCol = new TableColumn<>("Last Name");
            lastNameCol.setMinWidth(100);
            lastNameCol.setCellValueFactory(
                    new PropertyValueFactory("lastName"));
    
            TableColumn emailCol = new TableColumn<>("Email");
            emailCol.setMinWidth(200);
            emailCol.setCellValueFactory(
                    new PropertyValueFactory("email"));
    
            final Callback, TableCell> cellFactory = new DragSelectionCellFactory();
            firstNameCol.setCellFactory(cellFactory);
            lastNameCol.setCellFactory(cellFactory);
            emailCol.setCellFactory(cellFactory);
    
            table.setItems(data);
            table.getColumns().addAll(Arrays.asList(firstNameCol, lastNameCol, emailCol));
    
            table.getSelectionModel().setCellSelectionEnabled(true);
            table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    
            final VBox vbox = new VBox();
            vbox.setSpacing(5);
            vbox.setPadding(new Insets(10, 0, 0, 10));
            vbox.getChildren().addAll(label, table);
    
            ((Group) scene.getRoot()).getChildren().addAll(vbox);
    
            stage.setScene(scene);
            stage.show();
        }
    
        public static class DragSelectionCell extends TableCell {
    
            public DragSelectionCell() {
                setOnDragDetected(new EventHandler() {
                    @Override
                    public void handle(MouseEvent event) {
                        startFullDrag();
                        getTableColumn().getTableView().getSelectionModel().select(getIndex(), getTableColumn());
                    }
                });
                setOnMouseDragEntered(new EventHandler() {
    
                    @Override
                    public void handle(MouseDragEvent event) {
                        getTableColumn().getTableView().getSelectionModel().select(getIndex(), getTableColumn());
                    }
    
                });
            }
            @Override
            public void updateItem(String item, boolean empty) {
                super.updateItem(item, empty);
                if (empty) {
                    setText(null);
                } else {
                    setText(item);
                }
            }
    
        }
    
        public static class DragSelectionCellFactory implements Callback, TableCell> {
    
            @Override
            public TableCell call(final TableColumn col) {
                return new DragSelectionCell();
            }
    
        }
    
        public static class Person {
    
            private final SimpleStringProperty firstName;
            private final SimpleStringProperty lastName;
            private final SimpleStringProperty email;
    
            private Person(String fName, String lName, String email) {
                this.firstName = new SimpleStringProperty(fName);
                this.lastName = new SimpleStringProperty(lName);
                this.email = new SimpleStringProperty(email);
            }
    
            public String getFirstName() {
                return firstName.get();
            }
    
            public void setFirstName(String fName) {
                firstName.set(fName);
            }
    
            public String getLastName() {
                return lastName.get();
            }
    
            public void setLastName(String fName) {
                lastName.set(fName);
            }
    
            public String getEmail() {
                return email.get();
            }
    
            public void setEmail(String fName) {
                email.set(fName);
            }
        }
    
    }
    

Maybe you are looking for