Copy link to clipboard
Copied
Hello,
Is there a way of iterating through all arguments passed to a server script (with soap) in a for-loop fashion?
So far I have been able to retrieve the argument values by using the following syntax;
var arg1 = app.scriptArgs.getValue("Argument_1"); var arg2 = app.scriptArgs.getValue("Argument_2");
But all the arguments passed to the server are dynamically build. So how could I retrieve each argument value?
Regards, Sjoerd
I don't know any AS3, but your code looks a bit odd:
params.scriptArgs = new Array();
params.scriptArgs.push({name:myName, value:myValue});
ws.RunScript(params);
That's not inside a loop, so you are just sending one arg? So why not use
params.scriptArgs.push({name: "arg", value:(myName+":"+myValue));
and then in ExtendScript:
var arg, myName, myValue;
arg = app.scriptArgs.get("arg").split(":");
myName=arg[0];
myValue=arg[1];
Of course this uses a literal ":" as a seperator -- if that might appear in your
...Copy link to clipboard
Copied
would this not do?
var allArgs = app.scriptArgs.getElements();
Copy link to clipboard
Copied
would this not do?
var allArgs = app.scriptArgs.getElements();
I tried that, but how to get the values of these?
Copy link to clipboard
Copied
I tried:
allArgs.toString():
and
allArgs[0].toString();
Result:
[object ScriptArg]
No value
Copy link to clipboard
Copied
stoereee,
getElements() creates and returns an array.
See details at:
http://www.indiscripts.com/post/2010/07/on-everyitem-part-2
And when you are at it part 1 is a recommended read as well.
Uwe
Copy link to clipboard
Copied
getElements() creates and returns an array.
I was aware it is returning an array. But it's not slightly clear to me how the read the value strings of the scriptArgs-Array
Copy link to clipboard
Copied
app.scriptArgs.getValue("Arg1") gives the value string of the passed name Arg1. When I use app.scriptArgs.getElements(), I get an array of all the passed names. How I can I get the values of these array passed names?
Copy link to clipboard
Copied
When I use app.scriptArgs.getElements(), I get an array of all the passed names.
You do?
I can't seem to make .getElements() do anything useful at all:
>> app.scriptArgs.get("alpha")
beta
>> app.scriptArgs.get("gamma")
delta
>> app.scriptArgs.getElements().constructor
function Array() {
[native code]
}
>> app.scriptArgs.getElements().length
1
>> app.scriptArgs.getElements()[0].constructor.name
ScriptArg
>> app.scriptArgs.getElements()[0].get("alpha")
beta
That is, I just get back a singleton scriptArg member in the array that's the same as the app.scriptArgs.
Copy link to clipboard
Copied
I can't seem to make .getElements() do anything useful at all
Is there a other way of iterating through all scriptArgs passed to a server script to get all values?
Copy link to clipboard
Copied
Is there a other way of iterating through all scriptArgs passed to a server script to get all values?
You say other as if there is a way at all -- which there does not seem to be.
Why are you using scriptArgs anyhow? Can't you use the native Javascript arguments?
In any case, you could try packing all your args into a single scriptArg. Or, you could have a scriptArg with a known value that was a list of all other scriptArgs...you do control both sides of this, right?
Copy link to clipboard
Copied
you do control both sides of this, right?
Yes, the args are set with Flex and sent with SOAP:
var ws:WebService = new WebService();
ws.loadWSDL("http://192.168.254.123:18383/service?wsdl");
ws.endpointURI = "http://192.168.254.123:18383";
ws.loadWSDL();
var params:Object = new Object();
params.scriptLanguage = "javascript";
params.scriptFile = scriptFilepath.text;params.scriptArgs = new Array();
ws.RunScript(params);
params.scriptArgs.push({name:myName, value:myValue});
In any case, you could try packing all your args into a single scriptArg
How to pack all the args in one single scriptArG?
Copy link to clipboard
Copied
I don't know any AS3, but your code looks a bit odd:
params.scriptArgs = new Array();
params.scriptArgs.push({name:myName, value:myValue});
ws.RunScript(params);
That's not inside a loop, so you are just sending one arg? So why not use
params.scriptArgs.push({name: "arg", value:(myName+":"+myValue));
and then in ExtendScript:
var arg, myName, myValue;
arg = app.scriptArgs.get("arg").split(":");
myName=arg[0];
myValue=arg[1];
Of course this uses a literal ":" as a seperator -- if that might appear in your name or value, you'd have a problem. If so there are a hundred ways to solve it, probably the easiest way is to use the .toSource() method [how does that work in AS3?] to bundle it all together. Similarly if you're passing an array.
Copy link to clipboard
Copied
Thank you John, this helps a lot.
Example:
params.scriptArgs.push({name:"argsNames", value:myNaams});
params.scriptArgs.push({name:"argsValues", value:myValues});
And then:
app.scriptArgs.get("argsNames").split(":");
app.scriptArgs.get("argsValues").split(":");
Find more inspiration, events, and resources on the new Adobe Community
Explore Now