【问题标题】:1067: Implicit coercion of a value of type void to an unrelated type Function1067:将 void 类型的值隐式强制转换为不相关的类型 Function
【发布时间】:2014-06-29 13:05:28
【问题描述】:

所以我的操作脚本出现了一些新手错误,我需要一些帮助来解决它。代码实现 Timer 更改将在给定的持续时间内更改文本。它接收到需要突出显示/更改的持续时间和 RichText 项目,并在给定时间内更改其颜色。这就是它的基本结构。

package
{
    import flash.events.Event;
    import flash.events.TimerEvent;
import flash.utils.Timer;

import spark.components.RichText;

    public class TextChanger
    {


        public function changeColorForDuration(Duration:int, Texter:RichText){

            var highlightTextForDuration:Timer = new Timer(1000, Duration);

    highlightTextForDuration.addEventListener(TimerEvent.TIMER_COMPLETE, textDehighlight(Texter));

            textHighlight(Texter);
            highlightTextForDuration.start();   

        }

        private function textHighlight(specificText:RichText):void{
            var textField:RichText = specificText;
            textField.setStyle("color", "#ED1D24");
        }
        private function textDehighlight(textToChange:RichText):void{
            var textField:RichText = textToChange;
            textField.setStyle("color", "#00000");
        }
      }
    }

您能提供的任何帮助将不胜感激。

谢谢。

【问题讨论】:

  • 你的Texter是什么?该类型对象的类或实例。请包含更多代码并告诉您错误的确切位置。

标签: actionscript-3 class apache-flex actionscript flex4.5


【解决方案1】:

调用addEventListener时,需要传入一个函数,而不是函数调用:

highlightTextForDuration.addEventListener(TimerEvent.TIMER_COMPLETE, textDehighlight);

你的监听函数需要看起来更像这样:

private function textDehighlight(e:TimerEvent):void{
    var textField:RichText = textToChange;
    textField.setStyle("color", "#00000");
}

当然,这需要您为textToChange 放置一个类变量。如果这不起作用,您可以使用匿名侦听器函数:

highlightTextForDuration.addEventListener(TimerEvent.TIMER_COMPLETE, function(e:TimerEvent):void {
  var textField:RichText = Texter;
  textField.setStyle("color", "#00000");
});

【讨论】:

  • 非常感谢,它成功了。匿名监听函数是最简单的实现。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-01
  • 2011-10-19
  • 2016-09-24
  • 1970-01-01
  • 2015-12-12
相关资源
最近更新 更多