TORONTO (AP) - “Freeheld,” a gay-rights drama about the turning tide of social justice, was shaped by the same currents of change it depicts.

In the course of making the true story about New Jersey police detective Laurel Hester’s fight for pension benefits for her domestic partner, Stacie Andree, the Supreme Court ruled in favor of marriage equality and one of the film’s stars, Ellen Page, came out.

“Freeheld,” the story of a landmark victory in an ongoing battle for LGBT rights, is part celebration, part inspiration.

“Whenever you have these really amazing moments of progress or advancement, there can be a backlash to that,” says Page, also a producer of the film. “It’s nice to have this film now to celebrate the joy and celebrate the progress, mixed with, of course, the backlash that comes from people that struggle with the LGBT community.”

“Freeheld,” which opens in theaters Friday, dramatizes the events of Cynthia Wade’s 2007 Oscar-winning short documentary of the same name. Hester, a 23-year police veteran played by Julianne Moore, was dying of terminal lung cancer when she sought to have her pension transferred on her death to Andree (Page), as would be the case for a married couple. A panel of county legislators - freeholders - initially refused, and the case became a national story.

The film, directed by Peter Sollett and penned by Ron Nyswaner, is about the reluctant entry of Hester and Andree - both humble, private people - into the public struggle of the gay rights movement. It occurred simultaneously with the rapid onset of Hester’s cancer; she died in 2006 at age 49, shortly after the freeholders reversed their ruling.

“It is so personal, so, so incredibly personal,” says Moore. “We were really entrusted with an awful lot.”

Such are the terms all involved with “Freeheld” use to describe an unusually emotional movie experience. Andree was involved with the film, meeting with Moore and Page, visiting the set and attending the film’s moving premiere at the Toronto International Film Festival.

It was also especially personal for Page, who joined the project several years before she, herself, came out in 2014. The 28-year-old actress credits “Freeheld” with helping her in her own struggles with being closeted.

“Laurel and Stacie are really incredible people who did something really extraordinary that created a profound ripple effect for change,” says Page. “To be part of a story that’s inspiring and also personally meaningful, of course, is a pretty wonderful opportunity to have.”

Moore said witnessing Page’s experience gave her a new perspective.

“Here was this young person who’s been dealing with this tremendously probably isolating experience, and how liberating it was for her to finally be playing someone in a same-sex relationship,” Moore says. “I’ve had plenty of friends who have gone through it, but it was personalized for me. I was touched by her and her vulnerability and her openness.”

Sollett, the director of “Nick and Norah’s Infinite Playlist,” went into production on “Freeheld” knowing the Supreme Court would likely take up the issue of gay marriage, with different results yielding much different climates for the movie’s release.

“If they rule against it, we thought, we’ll have a film that reminds people why it’s so important to continue to fight for this cause,” says Sollett. “And if they rule for it, we’d have a film that reminded people how critical it is to defend that cause and push even harder and further for equal rights.”

“Freeheld” also arrives at a time when progress is being measured on screen in Hollywood’s embrace of LGBT stories. “Freeheld” is joined this fall by a handful of high-profile films, including the 1950s lesbian romance “Carol” and the transgender true-life tale “The Danish Girl.” Such movies, of course, remain rare, and academic studies have illustrated how LGBT roles are seldom found in the industry’s most popular films.

As the writer of two gay-rights dramas spaced by 22 years, Nyswaner, who scripted the Oscar-winning “Philadelphia,” is uniquely qualified on rating the media’s progress. The door, he says, has hardly been “flung open.”

“When I pitch, I still, if there’s a gay main character, I have to justify that,” says Nyswaner, who also penned the 2003 transgender drama “Soldier’s Girl” for Showtime. “The question will be: Why is he gay? And I have to have a good answer. No one ever says, ‘Are they straight and if they are why?’ If he’s gay, it must be because the subject of the story is about being gay.”

For the filmmakers and cast, “Freeheld” may be a signpost in a movement, on screen and off. But it’s ultimately about honoring Andree and Hester.

“The whole of this life, you see her spending her life fighting for justice for everybody else,” Moore says of her character. “And at the end, all she cared about was justice for the woman she loved.”