PDA

View Full Version : Condensing My Code...



tomyknoker
09-26-2006, 11:47 PM
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);
}

BLiZZaRD
09-27-2006, 01:52 AM
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.

tomyknoker
09-27-2006, 01:54 AM
Any chance you could show me on the code? :/

BLiZZaRD
09-27-2006, 02:23 AM
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).

Twey
09-27-2006, 06:41 PM
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);
}
}