Authentication when WS is called in Flash _ 4: Array

Source: Internet
Author: User
Arrays may be the most common data type in various languages. Next, let's take a look at how to process arrays (or "Approximate" Data Types of arrays) When Flash interacts with ws ).
Let's fix it by repairing sample2.asmx. cs: Add a web method to sample2.asmx. cs:
[WebMethod]
Public string [] GetArray_1 (){
String [] strArr = {"Joe dog", "Liu Peng", "Chen Bo", "Zhang chengping", "Fei Ming", "Chen Gang "};
Return strArr;
}
This method returns a string array, which is compiled. In the flash web service window, you can see that this image is only partial. Click to view the complete image.


The data type returned by this method.
Let's process the accepted data in the AS script:
Function GetArray_1 (result ){
Trace ("the value returned by the ws method GetArray_1 is :");
Trace ("/////////////////////////");
For (var I = 0; I <result. length; I ++ ){
Trace (I + ":" + result [I]);
}
}
Cough! There is no difference from locally processed arrays.

In fact, in. net, we do not use much of the original Array data type. More is to use some of the "advanced" Data Types in the System. Collections namespace: ArrayList, Hashtable, and HybridDictionary. In ws + flash interaction, their processing is similar to array, however, flash also provides some complex classes and APIs, so that we can easily and conveniently process these complex data types.
First, let's take a look at one of the simplest applications of ArrayList. Add the web method GetArray_2 in sample2.asmx. cs:
[WebMethod (Description = "array call: ArrayList")]
Public ArrayList GetArray_2 (){
ArrayList strArr = new ArrayList ();
Int I = 0;
For (I = 0; I <100; I ++ ){
StrArr. Add ("strArr [" + I + "]");
}
Return strArr;
}
The processing and processing of the Flash client are similar to that of the common array, so the code is not listed. This image is only partial. Click to view the complete image.


The above is an example of complex data processing, as shown in.
First, let's take a look at the server implementation: first, add the web method GetArray_3 in sample2.asmx. cs:
[WebMethod (Description = "array call, including object")]
Public Car [] GetArray_3 (){
Car HG = new Car ("crown", 2004 );
Car JM = new Car ("beautiful", 2003 );
Car YK = new Car ("accord", 2004 );
Car BJS = new Car ("Picasso", 2002 );
Car [] carArr = {HG, JM, YK, BJS };
Return carArr;
}
Note where the Car class comes from? The following is the implementation of the Car class:
[Serializable]
Public class Car {
// Declare the field model and yearBuilt;
Public string model;
Public int yearBuilt;

// Define the constructor
Public Car (string model, int yearBuilt ){
This. model = model;
This. yearBuilt = yearBuilt;
}

Public Car (){

}
}
Note: The Car class must be serialized !!
Test this method in a browser and return the following XML files
<? Xml version = "1.0" encoding = "UTF-8"?>
<ArrayOfCar xmlns: xsd = "http://www.w3.org/2001/XMLSchema" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns = "http://www.dxlschool.com/ws/">
<Car>
<Model> crown </model>
<YearBuilt> 2004 </yearBuilt>
</Car>
<Car>
<Model> beautiful </model>
<YearBuilt> 2003 </yearBuilt>
</Car>
<Car>
<Model> accord </model>
<YearBuilt> 2004 </yearBuilt>
</Car>
<Car>
<Model> Picasso </model>
<YearBuilt> 2002 </yearBuilt>
</Car>
</ArrayOfCar>
Let's go back to Flash2004 and take a look at the client's processing, which is very simple:
Function GetArray_3 (result ){
// Define an array to accept Values Transmitted by ws
Var myDB: Array = result;
// Bind the array myDB to the DataGrid component gb_main.
Gb_main.dataProvider = myDB;
}

......

This. dbBind2_bt.onPress = function (){
Var op_7: PendingCall = myws. GetArray_3 ();
Op_7.onResult = GetArray_3;
}

Success! Hehe, dual ??!!! Hehe.

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.