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

[JS IDCS5] retrieve all scriptArgs

Participant ,
May 18, 2011 May 18, 2011

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

TOPICS
Scripting
3.7K
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

LEGEND , May 19, 2011 May 19, 2011

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

...
Translate
Guide ,
May 18, 2011 May 18, 2011

would this not do?

var allArgs = app.scriptArgs.getElements();

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 ,
May 18, 2011 May 18, 2011

would this not do?

var allArgs = app.scriptArgs.getElements();


I tried that, but how to get the values of these?

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 ,
May 18, 2011 May 18, 2011

I tried:

allArgs.toString():

and

allArgs[0].toString();

Result:

[object ScriptArg]

No value

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 ,
May 18, 2011 May 18, 2011

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

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 ,
May 18, 2011 May 18, 2011

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

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 ,
May 18, 2011 May 18, 2011

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?

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
LEGEND ,
May 18, 2011 May 18, 2011

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.

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 ,
May 18, 2011 May 18, 2011
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?

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
LEGEND ,
May 18, 2011 May 18, 2011

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?

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 ,
May 19, 2011 May 19, 2011
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();
params.scriptArgs.push({name:myName, value:myValue});

ws.RunScript(params);

In any case, you could try packing all your args into a single scriptArg

How to pack all the args in one single scriptArG?

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
LEGEND ,
May 19, 2011 May 19, 2011

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.

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 ,
May 20, 2011 May 20, 2011
LATEST

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(":");

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