PDA

View Full Version : Flash CS5 Auto Format stops my code working?


M1KE
04-23-2011, 01:25 PM
I have some code that looks like this:

level_btn.x = 50 + (i - 1) % 10 * 50;

it sets the x location of my level button. But this is in a for loop (that's what the 'i' is for.)
I run it and everything works perfectly, as it should, not a single problem.

Then I press the auto format button in the flash actionscript editor. (It's the button that adds all of the ; to the end of each line and other stuff)

Well that changes my code to this:

level_btn.x = 50 + i - 1 % 10 * 50;

thinking it's done me a favour but it hasn't. It's got rid of the brackets so it won't do the maths functions in the correct order.

I've tried adding more brackets in places and other stuff but I just don't know how to fix it. It's annoying because every time I press the auto format button I have to add the brackets in again. Does anyone know how to fix this bug in flash?

Zanzlanz
03-25-2012, 12:49 PM
Hello!
Were you able to find any ways to fix this?
I'm having a similar problem.


function movement(ev:Event):void {
if (isDown["left"] == 1) {
mainScreen[mainScreen.length-mainCharacterDepth][3] -= 5;
}
if (isDown["right"] == 1) {
mainScreen[mainScreen.length-mainCharacterDepth][3] += 5;
}
if (isDown["up"] == 1) {
mainScreen[mainScreen.length-mainCharacterDepth][4] += 5;
}
world.x+=mainScreen[mainScreen.length-mainCharacterDepth][3];
world.y+=mainScreen[mainScreen.length-mainCharacterDepth][4];
mainScreen[mainScreen.length-mainCharacterDepth][3]*=.3;
mainScreen[mainScreen.length-mainCharacterDepth][4]*=.94;
}


Turns into:

function movement(ev:Event):void {
if (isDown["left"] == 1) {
}
mainScreen[mainScreen.length-mainCharacterDepth][3] -= 5;
};
if (isDown["right"] == 1) {
}
mainScreen[mainScreen.length-mainCharacterDepth][3] += 5;
};
if (isDown["up"] == 1) {
}
mainScreen[mainScreen.length-mainCharacterDepth][4] += 5;
};
world.x += mainScreen[mainScreen.length - mainCharacterDepth][3];
world.y += mainScreen[mainScreen.length - mainCharacterDepth][4];
}
mainScreen[mainScreen.length-mainCharacterDepth][3]*=.3;
mainScreen[mainScreen.length-mainCharacterDepth][4]*=.94;
};

And this messes up my code so badly of course.
If I get rid of this function altogether, though, it works fine.