The “Toy Story” franchise has been around a good deal longer than the “Shrek” one, but on the basis of their most recent installments, it’s aged far more gracefully. This third episode isn’t consistent—the beginning and end don’t match the middle—but that central portion of the picture is laugh-out-loud funny.

“The Simpsons” once did a great episode—“A Streetcar Named Marge,” about Marge starring with Ned Flanders in the musical version of “A Streetcar Named Desire”—that included a subplot about Maggie’s escape from the Ayn Rand daycare center. Most of Michael Arndt’s script here has a similar focus. The initial reels of the third story has the gang’s owner, Andy (voiced by John Morris) packing up his stuff to go off to college and the toys worrying over their fate. When all of them save Woody (Tom Hanks) barely escape the garbage truck, they wrongly conclude that the boy intended to throw them out—a mistake, of course. But they decide to be donated to Sunnyside Days are instead, believing it will give them the playtime they so long for. Woody’s pleas that they break out with him go unheeded, and his own escape goes awry, landing him in the collection of little Bonnie (Emily Hahn), where he meets some new characters—“master thespian” hedgehog Mr. Pricklepants (Timothy Dalton) and lady dino Trixie (Kristen Schaal).

Meanwhile Sunnyside has turned into something quite different from the halcyon paradise for unwanted toys the newcomers expected. They’re subjected to the harsh handling of the little kids while the established toys are treated gently by the older ones. And Lots-o’-Huggin Bear (Ned Beatty), who welcomed them effusively, turns out to be a dictator lording it over the place with his henchmen, including—most amusingly—a screaming, cymbal-clashing monkey that presides over the security camera system and loudly warns Lotso of any escape attempts. And the bear manages to reprogram Buzz (Tim Allen) to be his new chief guard. So when Woody makes his way back to Sunnyside to bust his friends out, the task isn’t an easy one—but it is funny.

One of the best bits in all this is the on-again, off-again romance between Barbie (Jodi Benson), whom Andy’s sister tossed into the donation box, and Ken (Michael Keaton), a strutting clotheshorse already at Sunnyside and not everything he initially seems. But all the returnees—Mr. and Mrs. Potato Head (Don Rickles and Estelle Harris), Jessie (Joan Cusack), Rex the Dino (Wallace Shawn) and slinky Hamm (John Ratzenberger)—get moments to shine as well. And Allen goes to town in an inspired bit when Buzz accidentally gets switched to Spanish mode.

But the gag-filled, action-packed center of “Toy Story 3” is surrounded by material that goes for the heartstrings rather than the funnybone. The series has always had a schmaltz component as well as jokes, but in the bookend portions of this installment the percentage of it goes off the dial. The overarching theme here, of course, is moving on, which always has an element of regret to it. But the ways in which it’s treated here lacks the emotional resonance of, say, “Up.” The difficulty Andy’s mom has in dealing with his departure doesn’t register, partially because as usual the human figures are the least real. And the last reel—which involves an overly flamboyant escape sequence in a landfill, complete with a “kumbaya” moment, followed by a saccharine goodbye between Andy and his toys (with one last playtime), is a calculated tearjerker. The mixture of silliness to sentiment has become unbalanced. (Happily, the clips during the final credit crawls go back to the jokes.)

Still, “Toy Story 3” is a worthy finale to one of the screen’s best trilogies. As one would expect, the technical work as impeccable as the voice characterizations, and as with “Up,” the 3D effects are employed subtly, without the crude in-your-face moments the process ordinarily invites. And though theoretically the ending leaves room for a possible “next generation” continuation, one hopes the makers won’t go that route. Why court ruining a series that’s gone so well until now?