Fast-paced Flash ActionScript 3.0-communication with ASP. NET in the form of text, XML, and JSON

Source: Internet
Author: User
Package
{
Import flash. display. Sprite;
Import flash.net. URLLoader;
Import flash.net. URLRequest;
Import flash.net. URLVariables;
Import flash.net. URLRequestMethod;
Import flash. events. Event;

// JSON support
Import com. adobe. serialization. json. JSON;

Public class Net extends Sprite
{
Public function Net ()
{
// Communicates with ASP. NET in text format
ShowText ();

// Communicate with ASP. NET in XML format
ShowXml ();

// Communicate with ASP. NET in JSON format
ShowJSON ();
}

// Communicates with ASP. NET in text format
Function showText (): void
{
Var v: URLVariables = new URLVariables ("name = webabcd & age = 27 ");
Var r: URLRequest = new URLRequest ();
R. url = "http: // localhost: 1343/Web/Text. aspx ";
R. method = URLRequestMethod. GET;
R. data = v;

Var l: URLLoader = new URLLoader ();
L. load (r );
L. addEventListener (Event. COMPLETE, textCompleteHandler );
}

Function textCompleteHandler (event: Event): void
{
Var l: URLLoader = URLLoader(event.tar get );

Trace (l. data );
// Output: name: webabcd; age: 27
}

// Communicate with ASP. NET in XML format
Function showXml (): void
{
Var v: URLVariables = new URLVariables ()
Var r: URLRequest = new URLRequest ();
R. url = "http: // localhost: 1343/Web/Xml. aspx ";
R. method = URLRequestMethod. GET;
R. data = v;


Var l: URLLoader = new URLLoader ();
L. load (r );
L. addEventListener (Event. COMPLETE, xmlCompleteHandler );
}

Function xmlCompleteHandler (event: Event): void
{
Var l: URLLoader = event.tar get as URLLoader;
Var xml: XML = new XML (l. data );

For each (var v in xml. person)
{
Trace ("name:" + v. @ name + "; age:" + v. @ age + "; salary:" + v. salary );
}
// Output:
// Name: webabcd; age: 27; salary: 1000
// Name: webabcdefg; age: 37; salary: 2000
// Name: webabcdefghijklmn; age: 47; salary: 30
}

// Communicate with ASP. NET in JSON format
Function showJSON (): void
{
Var v: URLVariables = new URLVariables ()
Var r: URLRequest = new URLRequest ();
R. url = "http: // localhost: 1343/Web/JSON. aspx ";
R. method = URLRequestMethod. GET;
R. data = v;


Var l: URLLoader = new URLLoader ();
L. load (r );
L. addEventListener (Event. COMPLETE, jsonCompleteHandler );
}

Function jsonCompleteHandler (event: Event): void
{
Var l: URLLoader = event.tar get as URLLoader;

Var v: * = JSON. decode (l. data );

Trace ("Name:" + v. Name + "; Age:" + v. Age );
// Output: Name: webabcd; age: 27
}
}
}

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.