Cause: AS3 calls PHP and PHP returns an XML structure asynchronously. AS3 assigns some node values in the XML structure to an object and then passes the values to JS through interaction with JS.
Debugging process:
PS item is the xml returned by PHP:
Var obj_info: Object = new Object ();
Obj_info ["from"] = item... from;
Obj_info ["context"] = item .. text;
Trace ("UserMessage --> Message from service chat:" + obj_info );
Trace ("UserMessage --> Message from service chat from:" + obj_info ["from"]);
Trace ("UserMessage --> Message from service chat context:" + obj_info ["context"]);
This. dispatchEvent (new MessageEvent (MessageEvent. USERGETSUCCESS, obj_info); output here:
UserMessage --> Message from service chat: [object Object]
UserMessage --> Message from service chat from: [object Object]
UserMessage --> Message from service chat context: [object Object] the obj_info object is the Object passed to JS, and the JSON structure required by JS is: {"from ": "... "," context ":"... "}, both attribute values are of the string type.
Error detected: when calling a function in JavaScript, debug the function in three cases: 1. Do not pass the parameter to the function; 2. Pass a JSON of the correct type and structure as the parameter; 3. Upload an incorrect JSON type and structure as the parameter. After these three debugging, we found that if the JSON structure is incorrect, the JS function will not be executed. In this way, the problem is resolved to the parameters that Flash passes to JS. Compare the debugging output results of Flash, and confirm that after Flash obtains XML from PHP, it needs to be forcibly converted when assigning values to the JS parameter passed.
Solution: modify the assignment code:
Var obj_info: Object = new Object ();
Obj_info ["from"] = (item... from). toString ();
Obj_info ["context"] = (item... text). toString ();
Trace ("UserMessage --> Message from service chat:" + obj_info );
Trace ("UserMessage --> Message from service chat from:" + obj_info ["from"]);
Trace ("UserMessage --> Message from service chat context:" + obj_info ["context"]);
This. dispatchEvent (new MessageEvent (MessageEvent. USERGETSUCCESS, obj_info ));