2010-10-08 139 views
0

我正在使用Actionscript 2,我正在嘗試做一些看起來很基本的事情。AS2 - 從函數外部控制補間

基本上,我已經定義了一個函數內的Tween對象,並且我想從另一個函數中控制該補間。這樣做的最好方法是什麼?

這是最基本的方式我的代碼設置當前:

// Define the function with my tween: 
function updateSlide() 
{ 
var progTween:Tween = new Tween(progressBar, "_width", None.easeOut, 1, 155, slideTime, true); 
} 

// Manipulate that tween on a button press: 
playBtn.onPress = function() 
{ 
progTween.start(); 
} 

現在我敢肯定,它不工作,因爲它是不一樣的功能範圍內,但你會怎麼做,以使這項工作?某種全局變量或全局函數?我不習慣在AS2中工作,也不習慣編程 - 任何見解都會非常有幫助。提前致謝。

回答

0

呼叫progTween.start()在updateSlide()並調用updateSlide與playBtn.onPress()

 
// Define the function with my tween: 
function updateSlide() 
{ 
    var progTween:Tween = new Tween(progressBar, "_width", None.easeOut, 1, 155, 
    slideTime, true); 
    progTween.start(); 
} 

// Manipulate that tween on a button press: 
playBtn.onPress = function() 
{ 
    updateSlide(); 
} 
1
//Define the variable as golbal variable 

var progTween:Tween; 

// Define the function with my tween: 

function updateSlide() 
{ 

progTween = new Tween(progressBar, "_width", None.easeOut, 1, 155, slideTime, true); 

} 

// Manipulate that tween on a button press: 
playBtn.onPress = function() 

{ 

progTween.start(); 

}