I think lacarman's advise should probably read the other way around, as in change it if it's dirty and leave it if it's clean, if you want it to work for longer.
That couldn't be farther from the truth. I took automatic and manual trans in school, and this is what I learned:
If your car has a pinkish tint to it, you have coolant leaking into it. Since coolant is harmful to rubber components in your trans and the fluid is contaminated, you will have to replace everything rubber inside of it. If your fluid is only slightly dirty, you can flush it. If your trans fluid is dirty AND dark, you have something burning (like a locked stator or burned up torque converter clutch) that is in your trans. If you flush the fluid, it will damage it and you WILL have to rebuild the transmission. The same goes for a car with over 60,000 miles that hasn't had the trans flushed...don't flush it. With the amount of dirt in the trans, it will dislodge whatever shavings or metal pieces are in the trans and it won't shift the same and will fail after. If you have clean fluid, flush it after 20,000 - 30,000 miles and do it regularly to keep your trans performing the same way every time.
If your check engine light comes on, you should be able to get an error code to further your diagnoses.
That isn't necessarily the case, either. If it is a burned up clutch in the input housing of the transmission, then the computer won't detect any codes, it will be able to be used as diagnosis if you can read the real-time stats of the car while it's running; however, but never rely on the scan-tool to just pull codes and diagnose the car. Perfect example: if your brake on/off switch isn't functioning, your torque converter clutch won't engage. It will make the brake light come on your dash, but you might not have a code for the torque converter. You have to use the scan-tool for data to make that determination.