如何在 Flex/Actionscript3 中编写通用属性修改函数?
我对 Flex 很陌生,但对编程并不陌生。 我想编写一个通用事件处理程序,当我的所有文本输入框获得焦点时将调用该事件处理程序。 当他们获得焦点时,我想更改文本输入框的颜色。 当他们失去焦点时,我想恢复“非活动”颜色配置文件。 我可以为每个文本输入框编写一个 ActionScript 事件处理程序,但我们都知道这是蹩脚的。 :o) 那么,我需要的是一种访问调用事件处理程序的对象的方法。
在 Delphi 中,我编写了一个传入 Sender 对象的函数,允许我访问调用对象的属性。 我猜 ActionScript/Flex 有一个完全不同的架构,这就是为什么我很难做到这一点。
感谢期待!
I'm new to Flex, although not new to programming. I want to write a generic event handler that will be called by all my textinput boxes when they receive focus. When they have focus, I want to change the colour of the textinput box. When they lose focus, I want to restore the "inactive" color profile. I could write an ActionScript event handler for each textinput box, but we all know that's lame. :o) What I need, then, is a way to access the object which is calling the event handler.
In Delphi, I'd have written a function which passes in the Sender object, allowing me to access the calling object's properties. I'm guessing ActionScript/Flex has a completely different architecture, which is why I'm having difficulty doing this.
Thanks in anticipation!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该子类化 TextInput 并处理其中的焦点事件。 我认为这将是实现您正在寻找的目标的最简单方法,而无需任何复杂的代码。
You should subclass TextInput and handle the focus events in there. I think this would be the simplest way to achieve what you are looking for without having any complex code.
我希望我理解您的要求...您在谈论事件委托吗?
这对我有用:
I hope I'm understanding what you're asking for... are you talking about event delegation?
This worked for me:
如果您想更改聚焦输入框的外观,可以通过设置
focusSkin
属性来实现。 如果您希望这种情况在全局范围内发生,您可以在 CSS 文件中添加样式声明。在此 CSS 示例中,我将默认的 focusSkin (
mx.skins.halo.HaloFocusRect
) 替换为嵌入的 PNG 文件。TextInput 有一些用于更改焦点外观的属性,例如更改焦点皮肤的不透明度(
focusAlpha
属性)。 有关详细信息,请查看 TextInput 文档。If you want to change the look of the focused input box, you can do this by setting the
focusSkin
property. If you want this to happen globally, you can put a style declaration in your CSS file.In this CSS example I'm replacing the default focusSkin (
mx.skins.halo.HaloFocusRect
) with an embedded PNG file.TextInput has a few properties for altering the look of the focus, like changing the opacity of the focus skin (
focusAlpha
property). Check the TextInput documentation for more info.