you have to enter the country first that gave you the visa.. so fly via spain and just transit
Not correct.
You have to apply for your visa at the embassy of the country which you intend to enter first OR in which you intend to spend the most time. Once you have a Schengen visa you can enter anywhere.