Copy link to clipboard
Copied
Can someone explain how to pass a var trough functions?
Daniel
Do you mean something like this?
var itemsearchcount = null;
previewdata();
nextviewdata();
function previewdata(){
// do something
itemsearchcount = 1;
return itemsearchcount;
};
function nextviewdata(){
// do something more
alert(itemsearchcount);
};
Copy link to clipboard
Copied
Pass as named arguments…? If you are passing many ( say from dialog input ) then I put them in an Object() and pass that as agrument…
Copy link to clipboard
Copied
Hi Mark, thanks for your reply, here's an example of wat i mean, i want to pass the itemsearchcount var from one button to another inside a function.
Is this possible, could you show me.
function previewdata(){
datapreview.backgroundgroup.backgroundgroupmarge.searchdata.searchdatapreviousBtn.onClick = function () {
var itemsearchcount = 1;
};
datapreview.backgroundgroup.backgroundgroupmarge.searchdata.searchdatanextBtn.onClick = function () {
alert(itemsearchcount);
};
};
It is just part of the function just to make it clear.
Thanks Daniel
Copy link to clipboard
Copied
Do you mean something like this?
var itemsearchcount = null;
previewdata();
nextviewdata();
function previewdata(){
// do something
itemsearchcount = 1;
return itemsearchcount;
};
function nextviewdata(){
// do something more
alert(itemsearchcount);
};
Copy link to clipboard
Copied
This worked for me, but it should be possible to create a var within a function and then call the var within a other function.
Thanks Daniel
Copy link to clipboard
Copied
No, that's not possible.
Define one or more empty (global) var before you go into a function. You can use them later (also in a function and give back to others).
IMHO a (local) var, which was created in a function is always undefined outside of this function.
Copy link to clipboard
Copied
that example worked by using Global variables, by definition variables declared inside a function are visible only within such function...I don't completely understand what you're trying to accomplish but from your code snippet above, maybe you want something like this?
is this the reference to your button? consider using variables for buttons if you need to refer to them later in your code
datapreview.backgroundgroup.backgroundgroupmarge.searchdata.searchdatapreviousBtn
var win = new Window ("dialog", "test dialog");
var prevBtn = win.add ("button", undefined, "prev");
var nextBtn = win.add ("button", undefined, "next");
prevBtn.onClick = function () {
this.itemsearchcount = 1;
}
nextBtn.onClick = function () {
alert(prevBtn.itemsearchcount);
}
win.show();
Copy link to clipboard
Copied
I would still do like so…
main();
function main() {
var win = new Window ("dialog", "test dialog");
var prevBtn = win.add ("button", undefined, "prev");
var nextBtn = win.add ("button", undefined, "next");
var count = 0;
prevBtn.onClick = function () {
count++
alert( count);
}
nextBtn.onClick = function () {
count--
alert( count);
}
win.show();
};
alert( count ); // Undefined
Copy link to clipboard
Copied
Or this?
function testFunc(varInfo) {
alert("varInfo " + varInfo);
}
//
testFunc(5)
testFunc("hi")
Edit: unless it was supposed to be through functions as in from one to another?
Find more inspiration, events, and resources on the new Adobe Community
Explore Now