The second sentence is the correct one.
As but doesn't make sense, when would be saying at the same time and once would be saying afterwards.