Shorter code

function myfunction(object1,para2,para3) {
   if (!object1.initialized) {
      object1.myProperty = para3;
      object1.anotherProperty = para2;
      para2 = 1;
      object1.ratio = 30;
      object1.initialized = true;
   }
   else {
      object1.ratio++;
      ...more code here...
   }
}

Is there a shorter code for this? It may look short but the function I actually made is much more complicated and longer that the code above.

Is there a way to type ‘object1’ once?

[edit]I edited this to show the code more clearly * Jubba :thumb:

you cannot shorten that code significantly.

You can, however, look up <b>with</b> in your ActionScript Dictionary =).

if object already has those values for it defined before they are being assigned there, you can say

with(object1){
myProperty = para3;
anotherProperty = para2;

}

otherwise… no

try

function myfunction(object1,para2,para3) {
with(object1) {
        if (!initialized) {
                myProperty = para3;
                anotherProperty = para2;
                para2 = 1;
                ratio = 30;
                initialized = true;
        }
        else {
                ratio++;
                ...more code here...
        }
}
}

im not sure if that’ll work, try it anyways…

[edit]

beat me to it…

This is the actual code:

function calculateColor(targetObject,targetObjectColor,targetColor) {
if (!targetObject.notInitialized) {
targetObject.targetColor = targetColor;
targetObject.ratio = 30;
targetObject.targetColor = targetObject.targetColor.toString(16);
hexToRgb(targetObject,targetObject.targetColor);
targetObject.targetR = targetObject.r;
targetObject.targetG = targetObject.g;
targetObject.targetB = targetObject.b;
targetObject.oldColor = targetObjectColor.getRGB().toString(16);
hexToRgb(targetObject,targetObject.oldColor);
targetObject.oldR = targetObject.r;
targetObject.oldG = targetObject.g;
targetObject.oldB = targetObject.b;
targetObject.xyzR = Math.max(targetObject.targetR,targetObject.oldR) - Math.min(targetObject.targetR,targetObject.oldR);
targetObject.xyzG = Math.max(targetObject.targetG,targetObject.oldG) - Math.min(targetObject.targetG,targetObject.oldG);
targetObject.xyzB = Math.max(targetObject.targetB,targetObject.oldB) - Math.min(targetObject.targetB,targetObject.oldB);
targetObject.asdfR = Math.floor(Math.abs(targetObject.xyzR/targetObject.ratio));
targetObject.asdfG = Math.floor(Math.abs(targetObject.xyzG/targetObject.ratio));
targetObject.asdfB = Math.floor(Math.abs(targetObject.xyzB/targetObject.ratio));
targetObject.notInitialized = true;
}
else {
if (targetObject.ratio > 0) {
targetObject.ratio–;
if (Math.max(targetObject.targetR,targetObject.oldR) == targetObject.targetR) {
targetObject.oldR += targetObject.asdfR;
}
else {
targetObject.oldR -= targetObject.asdfR;
}
if (Math.max(targetObject.targetG,targetObject.oldG) == targetObject.targetG) {
targetObject.oldG += targetObject.asdfG;
}
else {
targetObject.oldG -= targetObject.asdfG;
}
if (Math.max(targetObject.targetB,targetObject.oldB) == targetObject.targetB) {
targetObject.oldB += targetObject.asdfB;
}
else {
targetObject.oldB -= targetObject.asdfB;
}

	}
	else {
		targetObject.oldG = targetObject.targetG;
		targetObject.oldB = targetObject.targetB;
		targetObject.oldR = targetObject.targetR;
		targetObject.onEnterFrame = null;
	}
	changeColor(targetObject,targetObjectColor);
}

}

Could I still change this?

*Originally posted by senocular *
**if object already has those values for it defined before they are being assigned there…
**