If I believe right, blue flames are hotter than red ones and if I recall correctly it's because blue tend to ultraviolet. Then why is the sun, which's capable of warming whole planets, red instead of blue?
The comparison with flames is a bit misleading. Flames look yellow when they have have particles of unburnt carbon in them, and they look blue when there is no unburnt carbon present. The amount of unburnt carbon decreases as the flame gets hotter, so blue flames are indeed (usually) hotter than yellow flames. But this is not a fundamental property of the flame. It's due to the unburnt carbon.
The Sun is not a flame as nothing is burning in it. Instead it is a plasma i.e. it is a gas of ionised hydrogen and helium atoms, and the colour is described by Wien's displacement law. The temperature of the surface is around 5,700K and in fact it is more or less white. We tend to see it as yellowish because the atmosphere scatters blue light, but if you look at the Sun from outside the Earth's atmosphere it looks white.
You can get blue stars, but to have a significant blue colour the stars have to be very hot indeed. The surface temperature needs to be in the range 10,000 - 20,000 K or 2 to 4 times hotter than the Sun. The amount of energy emitted by a star of temperature $T$ is proportional to $T^4$ (see the Stefan Boltzmann law) so if you doubled the temperature of the Sun (and kept it the same size) it would emit 16 times as much heat and rapidly roast us all to a crisp!
The light of the sun contains a mixture of wavelengths - as given by the Planck law. The spectral distribution looks like this:
As you can see, the intensity is biased slightly towards the blue/violet part of the spectrum. However, as we evolved, we have learnt to interpret that mix of colors as "white". Strangely enough, when you are in a room illuminated by tungsten (incandescent) lights, when you see a piece of white paper you will have no trouble identifying it as "white" also. Yet the objective color is much more red/yellow (this is why cameras these days have AWB - automatic white balance - and why you used to have a "tungsten filter" that you would put on your film-based camera if you wanted to shoot slide film indoors: if you didn't, the images would come out looking horribly red).
The surface of the sun is around 5,700 degrees. The sun radiates all colors of the visible spectrum. The sun radiates like a black body and its spectrum is shown below.
The sun does emit blue light but it also emits red and the other colors with almost the same intensity. A mixture of all the colors results in white light. As the temperature decreases, the peak moves to the right and the sun would start to appear red. Likewise, as you said, if the sun was hotter, the peak would move left and the sun would start to appear blue as the peak approached the ultraviolet part of the spectrum.