Skip to main content
migueld83371718
Inspiring
June 11, 2019
Answered

Event not firing on button click

  • June 11, 2019
  • 1 reply
  • 3028 views

I'm trying to fire an event on an onclik inside a button, but the event does not fire. The button is inside a vue component and I am importing the function from another file.This is my code:

const csi = new CSInterface();

csi.addEventListener("com.my.extension.id.folderSelected", function(e){

    alert('event fired')

});

//The imported function

function collect(){

    let prompt = 'Select folder';

    var path = esHandler(`KT.selectFolderDialog("${prompt}", true)`)

        .then(function (res){

            var event = new CSEvent("com.my.extension.id.folderSelected", "APLICATION");

            event.data = res;

            csi.dispatchEvent(event);

    });

}

//Handler function for the asyncronicous behavior

function esHandler(script){

    return new Promise(function(resolve, reject){

        csi.evalScript(script, resolve);

    });

}

The promise is resolved and the code within "then" is executed , but the alert within the "addevEntListener" is not executed.I have tried changing the scope of the CSEvent to "GLOBAL", but still not firing.The above code is all in the same file. What could be the problem? What am I doing wrong?

This topic has been closed for replies.
Correct answer Justin Taylor-Hyper Brew

I do't think that's that, since the code is executed when you click on the button. Maybe it could be happening is that the function is losing the context when called from the component ?. This is the code of the Vue component:

<template>

    <div>

        <button  @click="collect">Collect</button>

    </div>

</template>

<script>

import collect from '../js/kt/collector.js'

export default {

    name:'dev-ae',

    methods: {

        collect(){

            collect()

        }

    }

}

</script>


Is there a reason it needs to be a CSEvent() if you're not calling it from ExtendScript? If it's just from JS to JS, you can just use a standard CustomEvent() event like this:

document.addEventListener("com.my.extension.id.folderSelected", function(e){

    alert('event fired')

});

//The imported function

function collect(){

    let prompt = 'Select folder';

    var path = esHandler(`KT.selectFolderDialog("${prompt}", true)`)

        .then(function (res){

            document.dispatchEvent(new CustomEvent('com.my.extension.id.folderSelected', res));

    });

}

//Handler function for the asyncronicous behavior

function esHandler(script){

    return new Promise(function(resolve, reject){

        csi.evalScript(script, resolve);

    });

}

1 reply

erinferinferinf
Adobe Employee
Adobe Employee
June 11, 2019

Hi there

migueld83371718
Inspiring
June 11, 2019

Hi Erin, thanks for fast response

I'm targeting After Effects 2019. The code I posted is running inside the panel vm. It does not seem that the problem occurs within extendscript, since evalScript returns the expected result, and I can trace it once It's assigned to event.data. I guess that works different, but I've tried to communicate this After Effects extension with an Animate extension through vulcan messages, and it has worked.

To add more information, I'm using webpack to use hot reloading with Vuejs, so mybe its' the cause of the problem?

Justin Taylor-Hyper Brew
Community Expert
Community Expert
June 11, 2019

Can you post the code snippet connecting the collect() function to the button? Sounds like your issue is just the button binding.