得到一个错误1120~访问未定义的属性

时间:2009-11-15 05:31:02

标签: flash actionscript-3 timer

这不是典型的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();

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

这是一个范围问题。你从这一行调用'延迟'函数:

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
}
相关问题