The button in as3 is disable, And the click event is triggered!

Source: Internet
Author: User
Btntest. addeventlistener (mouseevent. Click, btntestclick); function btntestclick (E: mouseevent): void {trace ("I Have Been clicked again"); btntest. Enabled = false ;}

Let's not talk about anything.CodeAnd then test: button(Note: it refers to simplebutton rather than the button in the component)After being disable, the click event can still be triggered. Why is the inventor of as3 designed like this? I don't understand it, but since it does, it can only follow it.

 

To trigger a button event only once, the correct method is removeeventlistener.

 
Btntest. addeventlistener (mouseevent. click, btntestclick); function btntestclick (E: mouseevent): void {trace ("I Have Been clicked again"); btntest. enabled = false; btntest. removeeventlistener (mouseevent. click, btntestclick );}

Postscript:

Afterwards, I thought about why Adobe was designed like this? I think this may be the programming between adobe and Microsoft.Different philosophical viewsIn Adobe's view, event listening should only be responsible for event listening. Nothing else that has nothing to do with me can affect me, that isSingle responsibilityIn Microsoft's opinionMutual assistanceWhen the button is disabled, the event response should be stopped and the event response should be restored when the button is enabled.

In fact, there are many differences in this concept in flash and sliverlight. For example, in flash, if a Sprite registers the enter_frame event, no matter whether the sprite instance has been added to the display list, as long as it is new, the enter_frame event processing function will continue to run, and directly call removeeventlistener to stop event listening. In sliverlight, after a Custom User Control is new, as long as it is not added to the (Root) display container, its corresponding compositiontarget. the rendering event will not be triggered.

In addition, after carefully reading the official documentation, we found that if removeeventlistener is not used to handle the event, there is another attribute to disable the mouse event response.Mouseenabled, Put itSet both enabled and enabled to false.The mouse event does not respond.

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.