I pieced together some code to get this actionscripted tween button navigation. Using the tween class I was able to get the rollovers to function through actionscript and not a timeline tween. The goal of this excercise was to create a set of buttons that:
- have a motion tween
- When pressed stay highlighted
- When one of the other buttons is pressed triggers the button last to tween back.
- Play certain movie associated with the button in empty mc on the stage.
I was able to accomplish the first 3, but can’t figure out how to load the 3 different movies when the navigation is pressed.
Here is the code so far ::
stop();
import mx.transitions.;
import mx.transitions.easing.;
// This is an array, a list of the buttons used.
var myButtons = [this.myButton_1, this.myButton_2, this.myButton_3, this.myButton_4];
// Loops on all buttons from the first to the last one
for (var i=0; i<myButtons.length; i++) {
// Sets its original X value. This will be used later for reference.
myButtons*.originalX = myButtons*._x;
// When the mouse rolls over this menu option...
myButtons*.onRollOver = function() {
var ball_tween:Object = new Tween(this.fade1_mc, “_x”, Regular.easeInOut, -378, 0, .25, true);
};
// When the mouse exits the menu option… go back up.
myButtons*.onRollOut = function() {
var ball_tween:Object = new Tween(this.fade1_mc, “_x”, Regular.easeInOut, 0,-378.0, .25, true);
};
// When the mouse clicks… activate it!
myButtons*.onRelease = function() {
this._parent.activateItem (this);
// *** Add some function here or somewhere else to handle real button actions!
trace ("Hey, button "+this+" was clicked.");
};
}
this.activateItem = function(item) {
// Function that activates a button.
// Checks if there's an activated item already; if so, deactivates it.
if (this.currentItem != false) this.deActivateItem();
// Activates it, finally
this.currentItem = item;
var ball_tween:Object = new Tween(this.currentItem.fade1_mc, "_x", Regular.easeInOut, 0, 0, .25, true);
this.currentItem.enabled = false; // makes it a disabled button, so it won't receive mouse events
};
this.deActivateItem = function() {
// Deactivates the current activated menu item.
this.currentItem.enabled = true; // back to a normal button/movieclip
var ball_tween:Object = new Tween(this.currentItem.fade1_mc, “_x”, Regular.easeInOut, 0, -378, .25, true);
this.currentItem = undefined;
};
this.stop();