Sometimes when I bake cookies, they either come out too soft or they become rock hard. I have read somewhere that baking cookies with butter makes is spreadable in the oven and gives it crispy texture, while using shortening makes it firm in the oven and gives it a flaky texture. What if I can use both in any of the cookie recipe replacing it with 100% butter or shortening? I want my cookies to have melting in the mouth and flaky texture.
The texture of a cookie is based on much more than the fat used, shortening or butter. In fact, within some basic limits, they are fairly interchangeable in most cookie recipes, flavor not withstanding.
Switching to part or all vegetable shortening will not yield a flaky texture.
The method by which the ingredients are combined, and how the cookies are treated, mixed, or rolled is a dominant factor in the final texture.
As Sourd'oh points out, your variation is more likely to be a result of over-cooking or under-cooking. The individual size of each cookie can make a considerable difference, especially with very small cookies.
If you are getting inconsistency within the same tray, you may not have uniformly sized cookies. A cookie scoop or disher can help with that, as can practice.
To get a truly flaky texture, you would need to use a recipe and method specifically designed to create flakiness. These cookies are often built with a variation on the laminated methods used for biscuits, where butter is cut into the dough, and then moistened. When they are rolled out, the pieces of butter flatten into layers, separating the flour layers, and providing the flakiness.
You certainly can use a combination of butter and shortening in most recipes. The key difference is the melting point of each. Butter melts at a lower temperature, so the cookies will begin to spread before the starch and eggs set. Shortening melts at a higher temperature so the starch and eggs will begin to set up before the shortening melts. Neither one of these will make your cookies "rock hard" though, that's more likely from them being overbaked.
You can replace shortening 1 for 1 with butter in most cookies. I commonly replace up to half or all of the butter in a cookie recipe with shortening. (I like to get shortening stick form for this; to simplify measuring.) It's been my experience that using shortening instead of butter can reduce the greasiness of a cookie, though you will usually see a little less browning during baking. So start out by baking a batch with half the butter replaced by an equal volume of shortening.
But, if your cookies are either too hard or too soft, the main culprit probably isn't the presence of butter. The first thing I would look at is how you're measuring flour - too much flour will lead to hard cookies and too little will prevent the cookies from staying together. The most accurate way to measure flour is by weight with a scale. If you only have measuring cups (measure by volume), then the most accurate method of measuring would be to pour flour into the cup, and level it off the cup with a flat edge.
If your cookies are spreading too much, it's more likely that your dough is too warm (due to a warm room temperature); try chilling the formed cookies for 20 minutes in the refrigerator before baking. Also, it could be that your oven's temperature is too low; use an in-oven thermometer and perhaps a baking stone (or bricks, or any other thermal mass).