Web Analytics Made Easy -
StatCounter Moving Items At The Same Time - CodingForum

Announcement

Collapse
No announcement yet.

Moving Items At The Same Time

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Moving Items At The Same Time

    Hi All,

    I have this script, which basically moves my mc buttons to the left by a number of pixels, this happens to each button that is rolled over... What I want to try and achieve however is if right1 is hovered, I want right2, right3, right4 and right5 to move to the right, and if right3 is hovered, I want right1 and right2 to go left, and right4 and right5 to go right and so on... Here is the code I currently have
    Code:
     // Includes the tweening extensions.
    
    #include "mc_tween2.as"
    
    
    // Assigns each button its own functions.
    
    // Of course, these buttons were created at design time, on the Flash IDE itself.
    // Usually, you wouldn't do that with serious projects, you'd create them dinamically from some "template"
    // movieclip (or from some component).
    
    // This is an array, a list of the buttons used.
    var myButtons = [this.right_1, this.right_2, this.right_3, this.right_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[i].originalX = myButtons[i]._x;
    	myButtons[i].xGlowTo(0x2F0000, 1, 30, 1, 3, false, false, 0);
    
    	// When the mouse rolls over this menu option... go down just a bit.
    	// NOTICE: I'm not taking into consideration the problem of having the hit area going down and "moving" the
    	// mouse area and out of the button (possible rollover flicking). This is just a simple example afterall.
    	myButtons[i].onRollOver = function() {
    				this.tween("_x", this.originalX + 5, 1);
    	};
    	// When the mouse exits the menu option.. go back up.
    	myButtons[i].onRollOut = function() {
    		this.tween("_x", this.originalX, 0.5);
    	};
    	// When the mouse clicks.. activate it!
    	myButtons[i].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;
    	this.currentItem.alphaTo (100, 1); // makes it 'disabled'
    	this.currentItem.enabled = true; // 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
    	this.currentItem.alphaTo (100, 0.5); // back to its original opacity
    	this.currentItem.tween("_x", this.currentItem.originalX, 0.5); // back to its original position
    	this.currentItem = undefined;
    };
    
    this.stop();
Working...
X