0

In a Flex application I am trying to turn an Object into a QueryString such as name1=value1&name2=value2... But I am having trouble getting the names of the Objects children. How do I enumerate the names instead of the values?

Thanks

2 Answers 2

3

I'm guessing you're doing a for each(in) loop. Just do a normal for(in) loop and you'll get the names instead of the values:

for(var name:String in obj) {
  var value:* = obj[name];
  // do whatever you need
}
Sign up to request clarification or add additional context in comments.

2 Comments

If it's a concrete class instead of just an Object, see ObjectUtil.getClassInfo()
I believe for(in) still works on concrete classes, but it's generally more limited on what it returns. It will only pick up what those classes have set up as visible using the setPropertyIsEnumerable method.
1

Ok, first off, if you need that query string to actually query a server, you don't really need to get it yourself as this code will query the server for you

protected function callSerivce():void
{
    var o:Object = new Object();
    o.action = "loadBogusData";
    o.val1 = "dsadasd";
    service.send(o);
}

<mx:HTTPService id="service" url="http://www.somewhere.com/file.php" method="GET" showBusyCursor="true"/>

Will make a call to the server like this: http://www.somewhere.com/file.php?action=loadBogusData&val1=dsadasd

But in case you really want to analyze the object by hand, try using ObjectUtil.getClassInfo, it returns a lot of information including all the fields (read more on LiveDocs).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.