This In Flex Points

Source: Internet
Author: User

In order to facilitate comparison and narration, let's start with the simplestJS + htmlCode:

< Input Type = "Button" Value = "Test" ID = "Htmbtn" Onclick = "Alert (this. ID )" >

Usage JS + html OfProgramEveryone knows, here's This Point to Html Component itself, so This. ID Display as expected "Htmbtn" .

However Flex3 When you write an event listening function, This The keyword will point Application , And Does not point to the component that triggers the event itself On ( JS + html Completely different ):

For example:

< MX: ComboBox Name = "TTT" Change = "Alert. Show ('you have change the data! '+ This. selectedlabel )" >
< MX: dataprovider >
< MX: String > Dogs </ MX: String >
< MX: String > Cats </ MX: String >
< MX: String > Mice </ MX: String >
</ MX: dataprovider >
</ MX: ComboBox >

This. selectedlabel no theme is found. Because This does not point to this ComboBox !!!

how can we find the component that triggers the event? flex provides event. currenttarget to specify the current component that triggers the event, as follows:

< MX: ComboBox Name = "TTT" Change = "Alert. Show ('you have change the data! '+ Event. currenttarget. selectedlabel )" >
< MX: dataprovider >
< MX: String > Dogs </ MX: String >
< MX: String > Cats </ MX: String >
< MX: String > Mice </ MX: String >
</ MX: dataprovider >
</ MX: ComboBox >

Or:

<MX: script><! [CDATA [
Private function changeevt (E: Event): void {
Alert. Show ('you have change the data! '+ E. currenttarget. selectedlabel )"
}
]></MX: script>

< MX: ComboBox Name = "TTT" Change = "Changeevt (event )" > < MX: dataprovider >
< MX: String > Dogs </ MX: String >
< MX: String > Cats </ MX: String >
< MX: String > Mice </ MX: String >
</ MX: dataprovider >
</ MX: ComboBox >

 

the official documents also provide special instructions, use event. currenttarget it is recommended that you specify the component type first, for example, textinput (E. currenttarget) to prevent running errors when a property of this component does not exist, you can see the code:

<? XML version = "1.0" ?>

<MX: ApplicationXmlns: MX= "Http://www.adobe.com/2006/mxml">

<MX: script><! [CDATA [

Import MX. Core. uicomponent;

Private function tihandler (E: Event): void {

/*
This code will report an error during running, but no error will be reported during compilation. Because textinput does not have the tmesis attribute at all
E. currenttarget. tmesis = 4;
*/

/*
The usage of this code can be found during compilation, and the error does not need to be reported during runtime.
Textinput (E. currenttarget). tmesis = 4;
*/

}

]></MX: script>

<MX: textinputID= "Ti1"Click= "Tihandler (event )"

Text= "This is some text. When you click on this control, the first three characters

Are selected ."/>

</MX: Application>

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.