Copy link to clipboard
Copied
Hello there.
I'm working on a UI that uses lots of eventListeners. I'd like to add and remove them depending on the state of the window.
To do this, I'm using callbacks:
.onActivate
.onDeactivate
The script below works like a charm when run from File>Scripts>Run Script File...
When saved in the /Scripts/ScriptUI Panels/scriptname.jsx and then run it from the Window menu in AE, the .onActivate callback doesn't seem to work.
At least not when just clicking the window.
But when You click the button first, the .onActivate callback is triggered.
The .onDeactivate callback works just as expected; it get's triggered when I click another part of the AE interface.
Any ideas?
{
function safeEventWindow(thisObj){
var win = thisObj instanceof Panel ? thisObj : new Window('palette',"Safe Event Window",undefined,{resizable:true})
win.alignChildren = ['fill','fill']
var mGrp = win.add('panel',undefined,'PANEL!')
mGrp.minimumSize = [200,200]
var btn1 = win.add('button',undefined,"I'm just a button, man.")
btn1.alignment = ['center','center']
btn1.onClick = switchText
var txt1 = mGrp.add("StaticText",undefined,"\\^___________^/")
txt1.alignment = ['center','center']
txt1.hide()
// FUNCTIONS
function switchText(event){
var state = txt1.visible
if(state) txt1.hide()
else txt1.show()
}
function mWin_refresh(){
win.layout.layout(true)
win.layout.resize()
}
// EVENT HANDLERS & FUNCTIONALITY
function startMouseListeners(event){
$.writeln("startingMouseListeners")
mGrp.addEventListener("mouseover",switchText)
mGrp.addEventListener("mouseout",switchText)
}
function stopMouseListeners(event){
$.writeln("stoppingMouseListeners")
mGrp.removeEventListener("mouseover",switchText)
mGrp.removeEventListener("mouseout",switchText)
}
win.onActivate = startMouseListeners
win.onDeactivate = stopMouseListeners
win.onResizing = mWin_refresh
//__INIT__
if(win instanceof Window){
win.show()
win.center()
}
mWin_refresh()
}
//__INIT__
safeEventWindow(this)
}
Checked on AE CC2014, windows 7 : onActivate does not work, onActivate triggers only when activating a widget (the button), but not the panel.
Side note : you should care when adding event listeners to a group/panel : the "mouseover" and "mouseout" can trigger for both the panel AND the static text (when it is visible)
Is it what you want ?
Xavier
Copy link to clipboard
Copied
Checked on AE CC2014, windows 7 : onActivate does not work, onActivate triggers only when activating a widget (the button), but not the panel.
Side note : you should care when adding event listeners to a group/panel : the "mouseover" and "mouseout" can trigger for both the panel AND the static text (when it is visible)
Is it what you want ?
Xavier
Copy link to clipboard
Copied
Aww, damn.. Is there another way to check if the Panel has been activated?
It really annoys me that it works for windows but not dockable panels.
Side note : you should care when adding event listeners to a group/panel : the "mouseover" and "mouseout" can trigger for both the panel AND the static text (when it is visible)
^I'm not sure what you mean? Is it: When I'm adding an eventListener to a group with another element in it, the event can be triggered twice, when the mouse is over both elements at the same time?
Copy link to clipboard
Copied
yes, when the mouse enters the static text when it is visible, it triggers
Copy link to clipboard
Copied
Hello! I'm Joel from the After Effects team. We've identified the problem and have prioritized a fix for this year, pending other higher priority work coming in.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Hi Joel,
Do you have some news on the bug fixing, because we are in the version 14.2 and the problem remain the same.
Tks for feedback
Copy link to clipboard
Copied
It has been 5 years and this hasn't been solved. 😕
Find more inspiration, events, and resources on the new Adobe Community
Explore Now