flex - Enumerate the properties of an AS3 object that may or may not be dynamic -
To send a POST request I have to calculate all the properties of a given object. This object can not be dynamic or may be. I'm looking for the most beautiful solution this is what I've got so far:
function createURLVariables (params: object): URLVariables {// solution: Flash Player does a GET If no parameters are passed in Param = = force post: true}; Var vars: URLVariables = new URLVariables (); Var property name: string; Var attribute list: XMLList = Description type (parameter) .. variable; Var Property Lamps: int = propertyList.length (); // A dynamic object will not return the attributes in this property if (Propertyist Lingti & gt; 0) {for (var i: int; i & lt; propertyListLength; i ++) {propertyName = propertyList [i] @ Name; Vars [propertyName] = Counselor [property name]; }} Else {for (propertyName in params) vars [propertyName] = params [propertyName]; } Returns Wars; }
One potential problem is that it will not return the attributes for the gates.
I took it in the JSON encoder. You have to modify it according to your needs, but you should give an idea to work with it. Note that there are some recursions here (convert to call, which you may not need:
/ ** * Converts an object to the Jasonan string equivalent * * @ The ultimate o convert For object * @ layer, JSON string representation of & lt; code & gt; o & lt; / code & gt; * / private function object toastring (o: object): String {// Object's Jasonstring Val var: String = ""; / / If o a class instance or plain object T var classInfo: XML = descriptionType (o); if (classInfo. @ Name.toString () == "object") {/ o in the value of [O] loop below - store it as a variable // In order to convert the value of Val values to the value of the value to be converted to the value of the value of the value (value): To see the allocation value for a variable, add value to the value = o [key]; // in the JSON string of the function If not (value is the function) {// Skip this key and try to continue another;} // When the length is 0 then we are adding the first item if // is a comma required (s.length & Gt; 0) {// If we have already added an item, then add the comma separator s + = ","} S + = escapeString (key) + ":" + convertorstring (value); }} And / or a class instance {// loop on all the variables and accessories in the class and // sort them with their prices. For every one (var v: classInfo in XML * .. (name () == "variable" || (name () == "accessor" // digit # 116 - Make sure the accessories are readable & amp; specialty; "Entry") .charAt (0) == "R"))) {// Issue # 110 - If [transient] metadata exists, then we should leave if (v.metadata & amp; amp; amp; & Amp; amp.metadata. (@name == "transient") Length ()> 0) {continue; } // When the length is 0 then we are adding the first item, // if no comma is necessary (s.length & gt; 0) {// We have already added an item, then add the comma separator + ","} S + = escapeString (v. @ Name.toString ()) + ":" + convertToString (o [v. @ Name]); }} Return "{" + s + "}"; }
Comments
Post a Comment