Source: http://www.riafan.com/article.asp? Id = 84
Fluorine's official help is to explain flex as3 (as3) and fluorine in amf0 and amf3 versions.. Net (hereinafter referred to.. Net). Here we will only introduce the amf3 version. The most convenient way to convert data types is to convert as3 custom objects to. Net Value objects.
1. Convert as3 to. Net (taking tonettype. mxml and tonettype. CS as an example)
1. Data of the basic type
For example, we use a method to send a person's basic information to the server: for example, name, age, and marital status, we can simply pass the name, age, and marital status as parameters of this method. The number of parameters and their front and back locations must correspond to. net. If there are more than one parameter, it is easy to make an error. In addition, it is often necessary to use. Net for conversion again. This type of data conversion is basically one-to-one, similar to HTTP service and Web Service, and does not reflect the advantages of remoting service technology. See the sendargs method in the source file.
2. array type
In the same case, if array is used as the parameter, the method will look much more concise. However, the elements in the array must be in the same position as those on the server. The as3 array is converted to the. NET ilist interface Data Type through fluorine. For more information, see sendarray.
3. Join array type
An array is actually an object, which allows us to dynamically add attributes. The parameter is changed to the attribute of the object, and the advanced parameters of the object are passed. There is no need to worry that the number and sequence of parameters in as3 and the methods in the. NET file must be consistent. The as3 associated array is converted to. Net hashtable through Fluorine. See assoarray method.
4. VO Data Type
Then, we can use fluorine to set up the custom object (such as person. as). net Value Object (VO) (such as person. CS) to implement as3 and.. Net mapping ). For example, in the sendvo method, the class names of these two classes can be different, and the attribute names and the number of attributes can be different (it is best to keep a good note, the same ). There are two methods to implement ing:
(1) register the alias of the class in the ActionScript class. Use remoteclass (alias = ". Net fully qualified class name ");
(2) Add the classmappings node to the Web. config file.
<Classmappings>
<Classmapping>
<Type>. Net full qualified name </type>
<Customclass> as3 fully qualified class name </customclass>
</Classmapping>
</Classmappings>
In some cases, the first method fails. You can try the second method. Obviously, it is most convenient to use a value object to transmit data to. net.
Of course, the bytearray data type is also very important. For example, the traditional method for binary encoding on the server side is very troublesome and inefficient. If fluorine is used to directly use the bytearray data type for as3 and. net, it is much more convenient and efficient.
========================================================== ======================================
Through the aboveArticleI chose strong data exchange between flex and. net, as long as the remoteclass (alias = ". Net fully qualified class name") is used in the Class Definition test.
Fortunately, the. NET Server uses the ADO. NET Entity Framework automatically generated entity definition. It seems that such a single object transfer method is feasible.
1. server side:
For example, if a database has a department table, the ADO. NET Entity Framework is used to automatically generate an object class. Pay attention to the "full qualified name" of the final entity class, for example: servicelibrary. Department
2. Flex client:
Create an as class in flex. We recommend that you end the class name with "VO". This will help distinguish between the flex client object and the server object. For example:
Package
{
[Remoteclass (alias = "servicelibrary. Department")]
Public class Vo
{
Public Function departmentvo (): void
{
}
Public var ID: number;
Public var name: string;
Public var parentid: number;
Public var Phone: string;
Public var Fax: string;
Public var des: string;
}
}
Note that there must be [remoteclass (alias = "servicelibrary. Department")] and alias must be available. The full name of the server cannot be incorrect. Otherwise, data conversion will fail.
3. Flex client remoting transmission:
>< br>
Import MX. events. flexevent;
Import flash.net. netconnection;
Import flash.net. responder;
Import flash. events. errorevent;
var NC: netconnection
protected function btn_clickhandler (Event: mouseevent): void
{< br> // todo auto-generated method stub
var resp: responder = new Responder (onsuccess, onfaild);
NC. call ("servicelibrary. sample. echo ", resp," DD ");
}
protected function application1_creationcompletehandler (Event: flexevent): void
{< br> // todo auto-generated method stub
NC = new netconnection ();
NC. objectencoding = objectencoding. amf3;
var gatewayurl: String = "http: // localhost: 2908/serverweb/gateway. aspx ";
NC. addeventlistener (netstatusevent. net_status, netstatehandle);
NC. connect (gatewayurl);
}< br> protected function netstatehandle (EVT: netstatusevent): void
{< br> This. label. TEXT = evt.info. tostring ();
}< br> protected function onsuccess (Re: string): void {
This. label. TEXT = Re;
}
Protected function onfaild (Re: string): void {
This. Label. Text = Re;
}
Protected function getdepartment_clickhandler (Event: mouseevent): void
{
// Todo auto-generated method stub
VaR resp: responder = new Responder (ondeptsuccess, ondeptfaild );
NC. Call ("servicelibrary. systemframework. departmentfacade. getdepartmentbyid", resp, 1 );
}
Protected function ondeptsuccess (Re: Object): void {
VaR dept: departmentvo = re as departmentvo;
This. lblname. Text = Dept. Name;
}
Protected function ondeptfaild (Re: string): void {
This. lblname. Text = Re;
}
]>
</FX: SCRIPT>
</S: Application>