If you advanced into the spearmen you shouldn't have ended up in a position like that. An advance is treated like a charge so you would move the closest stand into contact with the closest enemy. After that, move the other stands trying to maximize frontage within the limits of your move (20cm if you're advancing after the first round of combat, 10cm any round after that). You're only allowed to wrap around like you did in a pursuit (and when you do, make sure you don't box out one stand like you did as it can't attack).
In any case, you would have ended up in contact with both the spearmen and the archers, which is fine. They both would have fought (one stand each, -1 attack dice each due to flanking) and each wouldn't be able to claim support because they were being hit in the flank.