Helpful Information
 
 
Category: Flash
Condensing My Code...

It seems in my code I am repeating myself alot to just get simple actions to happen... Can anyone take a look and see if I can condense it down?


on (rollOver) {
_root.right1.colorTransformTo(30, 70, undefined, undefined, undefined, undefined, undefined, undefined, .1);
_root.right_text1.alphaTo(60, 1, "easeOutSine");
_root.right1.xSlideTo(335, 1);
_root.right2.xSlideTo(365, 1);
_root.right3.xSlideTo(395, 1);
_root.right4.xSlideTo(425, 1);
_root.right_text1.xSlideTo(710, 1);
_root.right_text2.xSlideTo(740, 1);
_root.right_text3.xSlideTo(770, 1);
_root.right_text4.xSlideTo(800, 1);
_root.rollOverSound.start()
}

on (rollOut) {
_root.right1.colorTransformTo(100, 0, 100, 0, 100, 0, 100, 0, 2);
_root.right_text1.alphaTo(20, 2, "easeOutSine");
_root.right1.xSlideTo(_root.right1.originalX, 1);
_root.right2.xSlideTo(_root.right2.originalX, 1);
_root.right3.xSlideTo(_root.right3.originalX, 1);
_root.right4.xSlideTo(_root.right4.originalX, 1);
_root.right_text1.xSlideTo(_root.right_text1.originalX, 1);
_root.right_text2.xSlideTo(_root.right_text2.originalX, 1);
_root.right_text3.xSlideTo(_root.right_text3.originalX, 1);
_root.right_text4.xSlideTo(_root.right_text4.originalX, 1);
}

Not really, since each is doing something different.

However, if you will be re-using the code in different spots, you can make them a function, attached to a button, and then just call the functions on the buttons when needed.

Any chance you could show me on the code? :/

Something like:



// this is the rollOver code.
nameOfbtn.onRollOver = function(){
//your rollOver code goes here
}

//This is the rollOut code
nameOfbtn.onRollOut = function(){
//Your rollOut codes here
}


Then just name your buttons: nameOfbtn (instance name).

Bearing in mind that I know nothing of ActionScript, you should be able to use a for loop and ECMAScript's idea of "objects as associative arrays:"
on (rollOver) {
_root.right1.colorTransformTo(30, 70, undefined, undefined, undefined, undefined, undefined, undefined, .1);
_root.right_text1.alphaTo(60, 1, "easeOutSine");
for(var i = 1; i < 5; ++i) {
_root['right' + i].xSlideTo(305 + (30 * i), 1);
_root['right_text' + i].xSlideTo(680 + (30 * i), 1);
}
_root.rollOverSound.start()
}

on (rollOut) {
_root.right1.colorTransformTo(100, 0, 100, 0, 100, 0, 100, 0, 2);
_root.right_text1.alphaTo(20, 2, "easeOutSine");
for(var i = 1; i < 5; ++i) {
_root['right' + i].xSlideTo(_root['right' + i].originalX, 1);
_root['right_text' + i].xSlideTo(_root['right_text' + i].originalX, 1);
}
}










privacy (GDPR)