【问题标题】:Got an error 1120 ~ Access of undefined property收到错误 1120 ~ 未定义属性的访问
【发布时间】:2010-12-16 17:45:47
【问题描述】:

这不是典型的 1120。我知道最好不要在时间轴上使用没有实例名称的按钮/MC。

不,这个问题存在于我从网上找到的脚本中构建的 I 计时器中。 undefined 属性和我要实现的定时器类延迟有关。

我想要实现的是让用户单击下一步按钮,等待 1 秒,然后滚动浏览下一个内容。我将代码放在条件语句中以减少代码量。

有一点需要注意,我正在使用 TweenLite 进行转换,如果这有什么不同的话

现在,下面的代码将向您展示计时器仅在下一个位置工作。我想最终将它添加到剩余的下一个位置和所有以前的位置,以便在滚动内容时会有一点延迟。

另外,我想重用相同的代码,以便当用户到达特定位置时,会有轻微的延迟和加载,和/或使图像或文本可见。

我将如何解决我最初的问题,然后简化代码以在整个项目中重用代码?

提前感谢您的帮助!

import gs.TweenLite;
import gs.easing.*;

var timer:Timer = new Timer(1500, 1);

next_mc.addEventListener(MouseEvent.CLICK, nextListener);
prev_mc.addEventListener(MouseEvent.CLICK, prevListener);
timer.addEventListener(TimerEvent.TIMER, delay); //I get the error here with "delay" 

prev_mc.visible = false;

function nextListener(event:MouseEvent):void {

 if (this.content_mc.slider_mc.x == 0) {

  function delay(event:TimerEvent):void {
   TweenLite.to(this.content_mc.slider_mc, 1, {x:-923.2, y:0, ease:Quart.easeInOut});
   prev_mc.visible = true;
  }
 } else {
  TweenLite.to(this.content_mc.slider_mc, 1, {x:-1872, y:0, ease:Quart.easeInOut});
  next_mc.visible = false;
 }
}

function prevListener(event:MouseEvent):void {
 if (this.content_mc.slider_mc.x == -1872) {
  TweenLite.to(this.content_mc.slider_mc, 1, {x:-923.2, y:0, ease:Quart.easeInOut});
  next_mc.visible = true;
 } else {
  TweenLite.to(this.content_mc.slider_mc, 1, {x:0, y:0, ease:Quart.easeInOut});
  prev_mc.visible = false;
 }
}

next_mc.buttonMode = true;
prev_mc.buttonMode = true;

timer.start();

【问题讨论】:

    标签: flash actionscript-3 timer


    【解决方案1】:

    问题在于“延迟”函数是在您的 nextListener 函数中定义的,因此在您的 timer.addEventListener(TimerEvent.TIMER, delay); 代码中无法访问它。我认为您的意思是将 timer.addEventListener(TimerEvent.TIMER, delay) 移动到下一个按钮处理程序中。

    【讨论】:

      【解决方案2】:

      这是一个范围界定问题。您正在从这一行调用“延迟”函数:

      timer.addEventListener(TimerEvent.TIMER, delay); //I get the error here with "delay" 
      

      但是延迟函数是在另一个函数中定义的,nextListener

      也就是说这条线看不到延迟功能。要解决此问题,只需将此行放在 nextListener 函数中:

      function nextListener(event:MouseEvent):void {
      // newly added ---v
      timer.addEventListener(TimerEvent.TIMER, delay); //I get the error here with "delay" 
      // rest of code
      }
      

      【讨论】:

        猜你喜欢
        • 2012-06-05
        • 1970-01-01
        • 1970-01-01
        • 2015-01-13
        • 1970-01-01
        • 2012-04-08
        • 2015-07-12
        • 2011-01-07
        • 2014-06-29
        相关资源
        最近更新 更多