2009-11-15 174 views
0

這不是典型的1120.我知道在時間線上沒有實例名稱的按鈕/ MC沒有問題。出現錯誤1120〜訪問未定義的屬性

不,這個問題存在於我從我在網上找到的腳本構建的I計時器中。未定義的屬性與我要實現的計時器類延遲有關。

我想要實現的是用戶點擊下一個按鈕,等待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(); 

回答

1

的問題是,「延遲」功能,您nextListener函數中定義的,所以它是不是在你的timer.addEventListener(TimerEvent.TIMER, delay);代碼訪問。我想你的意思是將移動到下一個按鈕處理程序中。

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 
}