views:

261

answers:

2

Hey all,

This is not your typical 1120. I know better than to have buttons/MCs without instance names on the timeline.

Nope, this problem resides in a I timer I built from script I found online. The undefined property is related to the timer class delay I want to implement.

What I'm trying to achieve is have the user click the next button, wait 1 sec., then scroll through the next content. I have the code sitting inside a conditional statement to reduce the amount of code.

One thing to note, I am using TweenLite for the transitions, if that makes any difference

Now, the following code will show you the timer only working work one next position. I want to eventually add this to the remaining next position and all the previous positions so that there will be a slight delay when scrolling through the content.

Also, I want to reuse the same code so when the user reaches a particular position, there will be a slight delay and load, and/or, make an image or text visible.

How would I solve my initial problem and then simplify the code to reuse the code throughout the project?

Thanks for the help in advance!

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();
+1  A: 

The problem is that the "delay" function is defined within your nextListener function, so it is not accessible in your timer.addEventListener(TimerEvent.TIMER, delay); code. I think you meant to move the timer.addEventListener(TimerEvent.TIMER, delay) inside of the next button handler.

Jacob
A: 

This is a scoping issue. You are calling the 'delay' function from this line:

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

but the delay function is defined in another function, nextListener.

That means that this line cannot see the delay function. To fix this issue, just put this line inside the nextListener function:

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