Helpful Information
 
 
Category: Flash
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
// 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();

You gave up on me already? Sheesh... LOL

Oh no not at all! Please keep helping me! I just had a meltdown overnight and got desperate :confused:

ROTF. I know, I was just messing with you. I am still working on it. I thought I had it, but when I tested nothing worked, LOL

Still thinking!

Someone somewhere posted this... It didn't really make sense to me but maybe it'll help?
Add an onPress to myButtons[i] where you set a globalvariable to i , _root.currentButton = i;

And before you set your onRollOut() you check if current i is equal to currentButton, if so, delete onRollOut, if less, make an onRollOut that goes to the left and if bigger make one that makes the buttons go to the right.

Well the first part means this:



myButtons[i].onRollOut = function() {
this.tween("_x", this.originalX, 0.5);
_root.currentButton = i;


I understand what they mean by the second part, but not how to impliment it... hmmmmm

No, thats not right.. They want you to make a:



on(press){
_root.currentButton = i;
}


Then they want you to set 3 onRollOut functions:



myButtons[i].onRollOut = function() {
this.tween("_x", this.originalX, 0.5);
}


then 2 more, one where the originalX is moved +1.5 and one where originalX is moved -.05

Then on your buttons put something like:



on(release){
if (i == 1){
function1();
else if (i >= 1){
function2();
else if (i <=1){
function3();
};
};
};


Something like that.

No, thats not right.. They want you to make a:



on(press){
_root.currentButton = i;
}


Then they want you to set 3 onRollOut functions:



myButtons[i].onRollOut = function() {
this.tween("_x", this.originalX, 0.5);
}


then 2 more, one where the originalX is moved +1.5 and one where originalX is moved -.05

Then on your buttons put something like:



on(release){
if (i == 1){
function1();
else if (i >= 1){
function2();
else if (i <=1){
function3();
};
};
};


Something like that.Hmmm I'm confused... Can you see that working?

About as much as you wanting to move all of them at the same time :p

Seriously though, what I just wrote was a mere coded example of what the OP had stated in words. Will it work? In theory, yes, in practicality? I don't know.

I still think you should do if/else statements for each button in that AS file.

using button names. so something like:

if _right1 is clicked, move _right1, _right2 to the right, etc....

But exactly HOW to do it will be the death of me! :confused:

Just a quick thought before I leave for work again...

why not use variables, locally. Give each button a value.

moveStatus = 0;

Then on the actual buttons:

(say on _right1):


on(press){
moveStatus = 1;
}


(say on _right2):


on(press){
moveStatus = 2;
}


Then:


on(release){
if (moveStatus == 1){
//_right1 through _right 5 .originalX + 1.5;
else if(moveStatus ==2){
//_right1 moves left, 2 through 5 .originalX +1.5;
//etc.

Just a quick thought before I leave for work again...

why not use variables, locally. Give each button a value.

moveStatus = 0;

Then on the actual buttons:

(say on _right1):


on(press){
moveStatus = 1;
}


(say on _right2):


on(press){
moveStatus = 2;
}


Then:


on(release){
if (moveStatus == 1){
//_right1 through _right 5 .originalX + 1.5;
else if(moveStatus ==2){
//_right1 moves left, 2 through 5 .originalX +1.5;
//etc.
So would I be changing all my code around?

No, nothing moved, just amended to. I will try to get back to you shortly with a proper code to try out.

I am stuck buddy. I have grow increasingly busy with paying clients on my sites. I should be able to get back to this in a few hours, unless you have a solution.

Sorry for the delay!










privacy (GDPR)