强制组件重绘其焦点
我还有一个“我该怎么做”的问题:) 假设我有一个组件并且想要在运行时更改它的焦点颜色。这是给你的一个例子(我已经排除了任何按钮等,以防止组件失去焦点,因为在这种情况下它会完美地改变它的颜色):
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
creationComplete="init()">
<mx:Script><![CDATA[
private function init():void {
//putting focus inside needed component
focusTest.setFocus();
focusTest.setSelection(0, 0);
// creates a new Timer
var minuteTimer:Timer = new Timer(1000, 30);
// designates listeners for the interval and completion events
minuteTimer.addEventListener(TimerEvent.TIMER, onTick);
minuteTimer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);
// starts the timer ticking
minuteTimer.start();
}
public function onTick(event:TimerEvent):void {
// displays the tick count so far
trace("tick " + event.target.currentCount);
if (focusTest.getStyle('focusColor') != 0x008CEA) {
focusTest.setStyle('focusColor', 0x008CEA);
} else {
focusTest.setStyle('focusColor', 0xFF0000);
}
//Update everything somehow :)
}
public function onTimerComplete(event:TimerEvent):void {
trace("Time's Up!");
}
]]></mx:Script>
<mx:TextInput id="focusTest"/>
</mx:Application>
我有什么: 计时器正在滴答作响。属性正在更改(您可以看到,例如在浏览器中切换选项卡时..当颜色更改时,只需捕获正确的状态)。
我想要什么:如何让这个焦点在没有魔法的情况下重新绘制(我已经尝试了所有方法,从“validate
”开始,我尝试过调用 < code>updateDisplayList() 在整个应用程序上,我尝试调用 styleChanged
... aggrr .. 我没主意了:))。
有什么想法吗?
像往常一样,我们非常感谢任何帮助:)
I'm having one more "How do I" question :)
Suppose I have a component and want to change it's focus color at runtime. Here's an example for you (I've excluded any buttons and such to prevent component from losing it's focus, cause in that case it changes it's color perfectly):
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
creationComplete="init()">
<mx:Script><![CDATA[
private function init():void {
//putting focus inside needed component
focusTest.setFocus();
focusTest.setSelection(0, 0);
// creates a new Timer
var minuteTimer:Timer = new Timer(1000, 30);
// designates listeners for the interval and completion events
minuteTimer.addEventListener(TimerEvent.TIMER, onTick);
minuteTimer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);
// starts the timer ticking
minuteTimer.start();
}
public function onTick(event:TimerEvent):void {
// displays the tick count so far
trace("tick " + event.target.currentCount);
if (focusTest.getStyle('focusColor') != 0x008CEA) {
focusTest.setStyle('focusColor', 0x008CEA);
} else {
focusTest.setStyle('focusColor', 0xFF0000);
}
//Update everything somehow :)
}
public function onTimerComplete(event:TimerEvent):void {
trace("Time's Up!");
}
]]></mx:Script>
<mx:TextInput id="focusTest"/>
</mx:Application>
What do I have: The timer is ticking. The property is changing (you can see that, e.g. while switching tabs in your browser .. just catch the right state, when the color is changed).
What do I want: How to make this focus to be redrawn without magic (I've tried all the methods, starting with "validate
", I've tried calling updateDisplayList()
on entire application, I've tried to call styleChanged
... aggrrh .. I'm out of ideas :)).
Any thoughts?
Any help, as usual, is greatly appreciated :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用
themeColor
和focusTest.drawColor(true)
它工作正常。你必须使用drawFocus()来重新着色,我不认为focusColor是Flex 3 setStyle属性(仅在Flex 4中使用)。很难发现,因为如果您使用不正确的 setStyle/getStyle 属性,Flex 不会抛出任何错误,它只是忽略它们!
完整代码:
If you use
themeColor
andfocusTest.drawColor(true)
it works fine. You have to use drawFocus() for it to recolor, and I dont think focusColor is a Flex 3 setStyle attribute (only used in Flex 4).Tricky to spot, because if you use incorrect setStyle/getStyle attributes Flex does not throw any errors, it just ignores them!
Full Code: