Use the demo of using methods as method parameters in flex ActionScript

Source: Internet
Author: User

Define a class

Public class mapserverproxy implements imapserverproxy {private VaR _ handler: function; // function-corresponding parameter method. Private VaR _ capabilities: imapservercapabilities; // real parameters of the parameter method. Public Function getcapabilities (): imapservercapabilities {return _ capabilities;} // you can specify a real parameter for the parameter method. Private function resulthandle (data: Object): void {var capabilities: imapservercapabilities = new mapserverrestcapabilities (data, _ request. URL); this. _ capabilities = capabilities; If (_ handler) _ handler (capabilities); // input a real parameter to the parameter method. ##### // Third, pass the real parameter to the method defined in step 1. The parameter types here must be consistent} // second, define a function object to store real parameters, assign a value to _ handler // main method, and the parameter type is a method. Public Function loadcapabilities (handler: function = NULL): void {// You can also input real parameters to the parameter method. This. _ handler = handler; // assign a value to the method variable: Assign the passed Method to the variable in the class .}}

Define a method as a parameter

// First, define a method M // define a method. The parameters of this method must be the same as the method type used to call this method. In the above example, ### mark the statement. Private function basemapserverloadedhandle (capabilities: imapservercapabilities): void {inittiledlayer (capabilities, true); // The parameter of this method has a specific value. Here, inittiledlaye is another method, which is not required .}

Define a class variable and call the methods in this class

// Fourth, pass M as an object to public var basemapserverproxy: imapserverproxy; basemapserverproxy. loadcapabilities (basemapserverloadedhandle) in method N; // use the method as a parameter. The real parameters in the parameter method are assigned values in the class.

--

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.