Switch: communication between flash and. Net (3): Application of loadvars object

Source: Internet
Author: User
I. Knowledge Introduction: (Flash MX Professional 2004 help document)
The loadvars class is used to transmit variables between flash applications and servers. You can use the loadvars class to obtain information about successful data loading, progress indication, and streaming data verification during download. The working principle of the loadvars class is very similar to that of the XML class. It uses methods load (), send (), and sendandload () to communicate with the server. The main difference between the loadvars class and the XML class is that loadvars transfers the name and value pairs of the Action Script, rather than the xml dom tree stored in the XML object. The loadvars class follows the same security restrictions as the XML class.

Ii. Main Application object knowledge:
1. loadvars. onload
Usage:
My_lv.onload = function (SUCCESS) {// here is your statement}
Parameters:
Success this parameter indicates whether the loading operation is completed successfully (true) or ended with failure (false ).
Return Value: A boolean value.
Note:
Event processing function, called when the loadvars. Load () or loadvars. sendandload () operation ends. If this operation succeeds, my_lv will fill in the variables downloaded by this operation, and these variables will become available when calling this processing function. This method is similar to XML. onload.
2. loadvars. sendandload ()
Usage:
My_lv.sendandload (URL, targetobject [, method])
Parameters:
The URL of the variable to be uploaded. If the SWF file that publishes this call runs on a Web browser, the URL must be in the same domain as the SWF file; targetobject receives the loadvars object of the downloaded variable. Method http get or POST method.
Return Value: string.
Note:
Publish the variables in the my_lv object to the specified URL. Download the server response, analyze it as the variable data, and place the result variable in the targetobject object. Variable publishing method is the same as loadvars. Send. Variables are downloaded to targetobject in the same way as loadvars. Load. In the SWF file of a player running earlier than Flash Player 7, the URL must be in the same super domain as the SWF file that publishes this call. For more information, see allow cross-Origin data loading. This method is similar to XML. sendandload.
Code and commentsActionscr platinum PT
Stop ();
VaR revar: loadvars = new loadvars (); // defines the response information of the receiving server (revar)
VaR sendvar: loadvars = new loadvars (); // defines the information sent to the server (sendvar)
Sendvar. NUMA = 1; // The variable NUMA = 1 that is initialized to the server
Sendvar. Numb = 2; // The variable numb that is initialized to the server = 2
Revar. value = 0; // The value of the initial receiving variable value = 0
Revar. onload = getserverinfo;
Sendvar. sendandload ("your url", revar, "Post ");
Trace ("server processing ...");
Function getserverinfo (success: Boolean)
{
If (SUCCESS)
{
Trace (revar. value)
}
Else
{
Trace ("server processing failed! ");
}
}

ASP. NET
Protected void page_load (Object sender, eventargs E)
{
If (request. Form ["NUMA"]! = NULL & request. Form ["NUMA"]! = NULL)
{
Try
{
Int A = convert. toint32 (request. Form ["NUMA"]. tostring ());
Int B = convert. toint32 (request. Form ["Numb"]. tostring ());
Int c = A + B;
Response. Write ("value =" + C. tostring ());
}
Catch
{
Response. Write ("value = server error! ");
}
}
Else
{
Response. Write ("value = data sending error! ");
}
}

Note:
Your ASP. the HTML code of the net page is deleted, and only the page declaration is left <% @ page... %>. Otherwise, response. data sent back to flash by write () will contain HTML code.

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.