Brian Hamill, Fox Searchlight Pictures
Will Ferrell, left, Radha Mitchell and Steve Carell star in "Melinda and Melinda," in which director Woody Allen again explores his obsessions.

Woody Allen has always called attention to his own obsessions. Younger women, jazz, old movies, infidelity, Manhattan, hypochondria — all there on film, many of them featured in every single one of the prolific neurotic's stories.

His most consistent preoccupation, though, is the blurred line between comedy and tragedy. His two greatest movies, "Hannah and Her Sisters" and "Crimes and Misdemeanors," were unbearably sad yet full of hilarious asides.

Now, with the engaging "Melinda and Melinda," Allen brings us inside his writer's brain as he continues the internal debate about comedy versus tragedy. Overcoming the handicap of an overt, writerly device, Allen crafts a warm comedy and a painful tragedy right before our eyes.

He is the magician who reveals all his tricks, and we still can't figure them out.

We start in a New York cafe, halfway into an erudite conversation among four intellectuals. One man says he heard a story about a beautiful, troubled young woman crashing a dinner party.

Immediately, Wallace Shawn as a comic writer and Larry Pine as a "serious" writer take over the tale, and say it could have played either way. Then they demonstrate it, and we watch alternating scenes of a romantic farce and romantic calamity, both starring Radha Mitchell as alluring "Melinda."

That Allen himself still fluctuates between the reassuring absurdity of life and the crushing hopelessness of existence is evident from the first scenes. In the tragedy, a drunk and strung-out Melinda bursts into a party where her actor friend is trying to impress a big-time director. This only gives the actor (Jonny Lee Miller) another excuse to fail — his drinking has already cost him other parts.

In the comedy, Melinda arrives at a dinner party strung out for the same reasons but quickly recovers to wolf down some food and flirt with the guys. This meal is hosted by a cold Amanda Peet and loopy Will Ferrell, who, distracted by Melinda's golden locks, promptly burns the Chilean sea bass.

Ferrell takes Allen's usual on-screen role, as the insecure Don Juan-nabe trailing out humorous asides while other people keep talking. He may be too much like his recent "Elf" and "Anchorman" leads, fairly silly for a sophisticated New York crowd, but he's a welcome (and younger!) switch from Allen himself.

Mitchell is effective in both stories, more so as a kind neighbor in the comedy than the floozy manic-depressive of the tragedy.

"Melinda and Melinda" is rated PG-13 for language and adult subject matter. Running time: 99 minutes.