gpt4 book ai didi

actionscript-3 - 如何取消 Halo/Spark TextInput 和 TextArea 组件中的编辑

转载 作者:行者123 更新时间:2023-12-01 02:49:03 25 4
gpt4 key购买 nike

我正在使用 Flex 4、ActionScript 3。

在 AdvancedDataGrid 组件中,当您在单元格中处于编辑模式时,您可以按 Escape 键取消编辑(即返回单元格中的前一个值)。

我原以为 Halo 和 Spark TextInput 和 TextArea 组件在编辑模式下会出现相同的行为,但惊讶地发现事实并非如此。

我查看了所有四个组件的属性,看看这是不是我需要配置的东西,但找不到任何东西。

这是需要编码的东西吗?

最佳答案

是的,这是必须编码的东西。这是我将采取的方法:

  • 创建一个扩展 TextInput 的自定义组件。我们叫它UndoTextInput .
  • 向 UndoTextInput 添加一个新变量以存储 TextInput 的原始文本。我们称之为 originalText .
  • focusIn 上添加事件监听器事件。在 focusIn事件处理程序,将当前文本值存储在 originalText 中多变的。
  • focusOut 上添加事件事件。在 focusOut事件,设置值originalText回到一个空字符串。
  • keyDown 上添加事件监听器事件。在事件监听器中,检查是否按下了 Escape ( Keyboard.ESCAPE ) 键。如果是,将文本重置回 originalText 中存储的内容。 .

  • 我希望这有帮助!

    更新:

    这是一个关于如何使用 Actionscript 类执行此操作的快速示例。根据需要随意修改。
    package
    {
    import flash.events.FocusEvent;
    import flash.events.KeyboardEvent;
    import flash.ui.Keyboard;

    import spark.components.TextInput;

    public class UndoTextInput extends TextInput
    {
    private var originalText:String = "";

    public function UndoTextInput()
    {
    super();
    this.addEventListener(FocusEvent.FOCUS_IN, focusInEventHandler);
    this.addEventListener(FocusEvent.FOCUS_OUT, focusOutEventHandler);
    this.addEventListener(KeyboardEvent.KEY_DOWN, checkKeyPress);
    }

    protected function focusOutEventHandler(event:FocusEvent):void
    {
    this.originalText = "";
    }

    protected function focusInEventHandler(event:FocusEvent):void
    {
    this.originalText = this.text;
    }

    protected function checkKeyPress(event:KeyboardEvent):void
    {
    if (event.keyCode == Keyboard.ESCAPE)
    {
    event.stopImmediatePropagation();
    this.text = this.originalText;
    }
    }
    }
    }

    关于actionscript-3 - 如何取消 Halo/Spark TextInput 和 TextArea 组件中的编辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6215729/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com