Four event handling methods of flex4

Source: Internet
Author: User

First, this example is for buttons. In fact, other components are similar.

First: directly write in the click attribute
<S: button label = "Click me" Click = "alert. Show ('clicked! ') "/>

Type 2: Embedded <s: Click> label
<S: button id = "B" label = "Click me once">
<S: Click>
B. Enabled = false;
MX. Controls. Alert. Show ('clicked! ');
</S: Click>
</S: button>
Third: Common Method Processing

<FX: SCRIPT>
<! [CDATA [
Import MX. Controls. Alert;

Private function handleclick (Event: mouseevent): void
{
B. Enabled = false;
MX. Controls. Alert. Show ('clicked! ');
}
]>
</FX: SCRIPT>

Method 4: add an event listener
<S: button id = "B" label = "Click me once">
<S: creationcomplete>
B. addeventlistener (mouseevent. Click, handleclick );
</S: creationcomplete>
</S: button>
<FX: SCRIPT>
<! [CDATA [
Import MX. Controls. Alert;

Private function handleclick (Event: mouseevent): void
{
B. Enabled = false;
MX. Controls. Alert. Show ('clicked! ');
}
]>
</FX: SCRIPT>

 

FinallyCodePaste

 

XML Code
  1. <Span Style="Font-size: Medium"><?XML Version="1.0" Encoding="UTF-8"?>
  2. <S: Application Xmlns: FX=Http://ns.adobe.com/mxml/2009"
  3. Xmlns: S="Library: // ns.adobe.com/flex/spark"
  4. Xmlns: MX="Library: // ns.adobe.com/flex/mx" Minwidth="955" Minheight="600">
  5. <FX: script>
  6. <! [CDATA [ 
  7. Import MX. Controls. Alert; 
  8.  
  9. Private function handleclick (Event: mouseevent): void 
  10. Alert. Show ('helloworld', 'hs '); 
  11. ]>
  12. </FX: script>
  13. <FX: Declarations>
  14. <! -- Place non-visual elements (such as services and value objects) Here -->
  15. </FX: Declarations>
  16. S: button x = "69" Y = "82" label = "button" click = "alert. show ('helloworld', 'hs '); " />
  17. <S: buttonX="170" Y="82" Label="Button">
  18. <S: Click>
  19. <! [CDATA [ 
  20. Alert. Show ('helloworld', 'hs '); 
  21. ]>
  22. </S: Click>
  23. </S: button>
  24. S: button x = "287" Y = "84" label = "button" click = "handleclick (Event) " />
  25. <S: button X="403" Y="83" Label="Button" ID="C" >
  26. <S: creationcomplete>
  27. C. addeventlistener (mouseevent. Click, handleclick );
  28. </S: creationcomplete>
  29. </S: button>
  30. </S: Application>
  31. span >
Related Article

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.