Can't figure out why this doesn't work right

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
Milad
Posts: 2
Joined: October 3rd, 2013, 10:13 am

Hi, I'm doing a video tutorial series from FXPHD on AEscripting and I've hit a brickwall. I've typed exactly what they have, but for some reason this isn't working right.


var myWindow = new Window ("dialog", "My Window");

myWindow.okButton = myWindow.add("button");
myWindow.okButton.text = "OK"
myWindow.cancelButton = myWindow.add("button");
myWindow.cancelButton.text = "Cancel"
myWindow.show();

myWindow.okButton.onClick = function() {
alert("OK");
myWindow.close();
};

myWindow.cancelButton.onClick = function() {
alert("Cancel");
myWindow.close();
};


2 things I've noticed when I run it is that it will show the window, but if you click on a button it won't do anything as if it won't let me run inline functions. If I turn those into 2 regular functions and define them after the onClick statements, then what happens is that when you click on one button, both alerts pop up as if it's running one function after another.

I know this is probably a silly question, but i'm at the start of this video and can't move on without finding out why it's acting this way. thank you guys.
willsummers
Posts: 1
Joined: October 23rd, 2013, 8:56 am

I ran into this exact same problem. These inline function will run if the entire script is put in an encompassing function like Main() and run that way.
bradon
Posts: 2
Joined: November 15th, 2005, 10:04 am

it seems to work fine if you put the show window at the bottom?

Code: Select all


var myWindow = new Window ("dialog", "My Window"); 

myWindow.okButton = myWindow.add("button"); 
myWindow.okButton.text = "OK" 
myWindow.cancelButton = myWindow.add("button"); 
myWindow.cancelButton.text = "Cancel"
 

myWindow.okButton.onClick = function() { 
alert("OK");
myWindow.close();
};

myWindow.cancelButton.onClick = function() { 
alert("Cancel");
myWindow.close();
};

myWindow.show();
Post Reply