Three methods for using ActionScript In Flex

Source: Internet
Author: User
In fact, similar to using JavaScript and other script files on a webpage, there are three main methods.
1. inline modeXML code {
DP. Sh. toolbar. copytoclipboard (this); Return false;
} "Href =" http://writeblog.csdn.net/# ">
  1. <? XMLVersion = "1.0" encoding = "UTF-8"?>
  2. <! -- Main. mxml -->
  3. <? XMLVersion = "1.0" encoding = "UTF-8"?> <Mx: ApplicationXmlns: MX = "http://www.adobe.com/2006/mxml" layout = "vertical">
  4. <Mx: buttonLabel = "Say hello" Click = "MX. Controls. Alert. Show ('hello, flying ')"/>
  5. </MX: Application>
<?xml version="1.0" encoding="utf-8"?><!--main.mxml --><?xml version="1.0" encoding="utf-8"?><mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"><mx:Button label="Say Hello" click="mx.controls.Alert.show('Hello,Flying')"/></mx:Application>

This method directly uses the as method as the attribute value of the event. Of course, this method generally has only one row, which is relatively simple. If you want to pass the logarithm to the method, this method is not desirable.
Note:
Alert. Show (''); single quotation marks are used here. Do not use double quotation marks.

2. Cascade MethodsXML code {
DP. Sh. toolbar. copytoclipboard (this); Return false;
} "Href =" http://writeblog.csdn.net/# ">

  1. <! -- Main. mxml -->
  2. <? XMLVersion = "1.0" encoding = "UTF-8"?>
  3. <Mx: ApplicationXmlns: MX = "http://www.adobe.com/2006/mxml" layout = "vertical">
  4. <Mx: buttonLabel = "Say hello" Click = "sayhello ('flying ')"/>
  5. <Mx: SCRIPT>
  6. <! [CDATA [
  7. Import MX. Controls. Alert;
  8. Private function sayhello (param_name: string): void {
  9. Alert. Show ("hello," + param_name );
  10. }
  11. ]>
  12. </MX: SCRIPT>
  13. </MX: Application>
<!--main.mxml --><?xml version="1.0" encoding="utf-8"?><mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"><mx:Button label="Say Hello" click="sayHello('Flying')"/><mx:Script><![CDATA[import mx.controls.Alert;private function sayHello(param_name:String):void {Alert.show("Hello, "+param_name);}  ]]></mx:Script></mx:Application>

This method puts the as method into the <mx: SCRIPT> </MX: SCRIPT> code block, uses the method as the event property value, and can pass parameters when calling the method, in this way, the as method is reused in a file.
3. External ConnectionXML code {
DP. Sh. toolbar. copytoclipboard (this); Return false;
} "Href =" http://writeblog.csdn.net/# ">

  1. <! -- Main. mxml -->
  2. <? XMLVersion = "1.0" encoding = "UTF-8"?>
  3. <Mx: ApplicationXmlns: MX = "http://www.adobe.com/2006/mxml" layout = "vertical">
  4. <Mx: scriptSource = "myfunction."/>
  5. <Mx: buttonLabel = "Say hello" Click = "sayhello ('flying ');"/>
  6. </MX: Application>
  7. // Myfunction. asimport
  8. MX. Controls. Alert;
  9. Private function sayhello (param_name: string): void {
  10. MX. Controls. Alert. Show ("hello," + param_name );
  11. }
<!--main.mxml --><?xml version="1.0" encoding="utf-8"?><mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"><mx:Script source="myFunction.as"/> <mx:Button label="Say Hello" click="sayHello('Flying');"/></mx:Application>// myFunction.asimportmx.controls.Alert;private function sayHello(param_name:String):void {mx.controls.Alert.show("Hello, "+param_name);}

The preceding method creates an as file for the AS method, sets this method to the source attribute value of the script element of the called file, and passes parameters when calling the method, this file can be called in multiple files, so that the AS method can be reused in multiple files.

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.