Jennifer Garner saved Ben Affleck's new movie 'The Way Back' when he "fell off the wagon".

Jennifer Garner

Jennifer Garner

The 47-year-old actress stepped in when her ex-husband when he sought treatment - after footage emerged of him looking intoxicated outside a Halloween party - and she called the film's director to make sure he didn't lose the role as recovering alcoholic Jack Cunningham in the upcoming sports drama.

Filmmaker Gavin O'Connor told 34th Street magazine: "Just as we started prepping the movie, Ben fell off the wagon. So he ended up going to rehab, and I didn't know if the movie was over.

"The studio certainly thought the movie was over. His ex-wife Jennifer Garner called me up, and told me that when he went to rehab, he took a basketball with him.

"She said, 'Gavin, he's asking you, please don't pull the plug on the movie, he really wants to do this.' "

Gavin explained that the most important thing was Ben's recovery and sobriety, and they made sure he was still able to take on the role.

He added: "So, he had about a week of detoxing, because he really went off the deep end, and after a week, I was able to go see him.

"We spent half a day together and figured out a way to do this that will work for him, because most importantly he needed to recover and needed to get his sobriety on track.

"That overtook everything. And then he got out the day before we started shooting. So we had a very raw, vulnerable guy showing up for our first day of shooting."

Ben's co-star, Will Ropp, recently revealed the 47-year-old actor would be accompanied back and forth from rehab during "the beginning" of shooting the movie as he battled his addiction.

He explained: "Everybody was very transparent from the beginning that he was in rehab at the beginning of the film.

"He had to have a sober liaison that would bring him to set and that would bring him back from [the] set."