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

Event not firing on button click

Participant ,
Jun 11, 2019 Jun 11, 2019

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?

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

Community Expert , Jun 12, 2019 Jun 12, 2019

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 Cus

...
Translate
Adobe Employee ,
Jun 11, 2019 Jun 11, 2019

Hi there

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
Participant ,
Jun 11, 2019 Jun 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?

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
Community Expert ,
Jun 11, 2019 Jun 11, 2019

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

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
Participant ,
Jun 12, 2019 Jun 12, 2019

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>

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
Community Expert ,
Jun 12, 2019 Jun 12, 2019

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);

    });

}

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
Participant ,
Jun 12, 2019 Jun 12, 2019
LATEST

That worked, I really didnt' need the CSEvent on that case. It was a bad understanding for my part of the CSEvents

Thanks Justin!

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