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
-
- <Span Style="Font-size: Medium"><?XML Version="1.0" Encoding="UTF-8"?>
-
- <S: Application Xmlns: FX=Http://ns.adobe.com/mxml/2009"
- Xmlns: S="Library: // ns.adobe.com/flex/spark"
-
- Xmlns: MX="Library: // ns.adobe.com/flex/mx" Minwidth="955" Minheight="600">
- <FX: script>
-
- <! [CDATA [
-
- Import MX. Controls. Alert;
-
-
-
- Private function handleclick (Event: mouseevent): void
-
- {
- Alert. Show ('helloworld', 'hs ');
-
- }
-
- ]>
-
- </FX: script>
-
- <FX: Declarations>
- <! -- Place non-visual elements (such as services and value objects) Here -->
-
-
- </FX: Declarations>
- S: button x = "69" Y = "82" label = "button" click = "alert. show ('helloworld', 'hs '); " />
- <S: buttonX="170" Y="82" Label="Button">
-
- <S: Click>
-
- <! [CDATA [
- Alert. Show ('helloworld', 'hs ');
-
- ]>
-
- </S: Click>
-
- </S: button>
- S: button x = "287" Y = "84" label = "button" click = "handleclick (Event) " />
- <S: button X="403" Y="83" Label="Button" ID="C" >
-
- <S: creationcomplete>
- C. addeventlistener (mouseevent. Click, handleclick );
-
- </S: creationcomplete>
-
- </S: button>
-
-
-
- </S: Application>
- span >