0
votes

I'm working in Actionscript 2, and I am trying to do something that seems to be basic.

Basically, i've defined a Tween object within a function, and i want to control that tween from another function. What's the best way of doing this?

This is the basic way i have the code set up currently:

// 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();
}

Now i'm sure it's not working because it's not within the same function, but what would you do to make this work? Some sort of global variable or global function? I'm not used to working in AS2, or with programming in general-- Any insight would be very helpful. Thanks in advance.

2

2 Answers

1
votes
//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();

}
0
votes

Call progTween.start() in updateSlide() and call updateSlide with 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();
}