Jon Hamm was up for a starring role in the smash hit movie “Gone Girl,” but wasn’t allowed to do the film because “Mad Men” creator Matt Weiner wouldn’t let him out of his contractual obligations to his series.

Hamm is still smarting from the career-hampering move to stop him from taking the role played by Ben Affleck, sources say. “Matt would not let Jon out of his contract to do ‘Gone Girl.’ Jon was really upset about it at the time — and is still upset, because he’s thinking about the future of his career as ‘Mad Men’ comes to a close.” Another source said Hamm couldn’t do the film due to “the ‘Mad Men’ shooting schedule.”

Hamm just completed 30 days in rehab for alcohol abuse before the final season of his acclaimed show. The actor told GQ about his future: “The one constant thing I’ve had in my career is now removed. And that’s an eye-opener: Are people still going to take me seriously? Am I just going to do romantic comedies for the rest of my life? What’s next? And I don’t know, you know? I wish I was smug enough to have had a grand plan.” His partner Jennifer Westfeldt said: “I think the darkness of [‘Mad Men’ character] Don [Draper] has weighed heavily on Jon.”

A source said if Hamm had been allowed to do “Gone Girl,” which made $368 million, “he’d be leaving the show with a hit movie and a gritty film role under his belt.”

Before rehab, Hamm was known in showbiz circles as a fun-loving but heavy drinker. “He was well-known in Hollywood for being a heavy drinker,” said a source, “which is why he needed to go to rehab. But the timing has a lot to do with his concerns for his career.”

Immediately after word of Hamm’s rehab stay, the actor’s admirably faced all his press obligations, looking healthy and addressing the show’s ending as well as his news with grace and charm.

Westfeldt has been absent from Hamm’s side at a series of “Mad Men” events. But a rep explained: “Unfortunately, Jennifer was not able to attend because of a serious illness in her family, on the heels of a recent death in her family.”

Weiner and Hamm’s reps declined to comment.