AS3 interaction with JS

Source: Internet
Author: User
Tags json object object php and tostring

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 ));

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.