There was good reason to think Mattel (MAT -1.88%) would offer up a second-quarter earnings surprise, and the toy maker didn't disappoint. Revenue rose 2% to $860 million compared to an expected 2% decline, and adjusted earnings came in at a loss of $0.25 per share, an improvement over last year's $0.29 per-share loss and significantly better than Wall Street's expected $0.35 per-share loss.

Investors who were paying attention could have profited nicely as Mattel's stock surged 13% on the results.

Woody and Buzz Lightyear from Toy Story 4

Toy Story 4 was the big story for Mattel this quarter. Image source: Mattel.

Still has work to do

It's clear the Toys R Us bankruptcy and liquidation that loomed so large last year is a dead issue today. While everyone hopes the comeback the toy store plans is a successful one, its absence from the market is no longer a factor in the results of the toy makers. Other retailers have stepped forward to expand their shelf space for toys, and that has made up virtually all of the loss in the void created by Toys R Us' demise.

Yet Mattel still has issues of its own it needs to work through. The American Girl franchise remains in a vortex of falling sales, down 22% in the quarter, though Mattel brought on a new division president and is planning for a turnaround in the back half of the year with new products and new pricing to attract customers. This seems like a project that will take a long time to resolve.

The Fisher-Price brand is another area where Mattel still has work to do. Sales were down 4% in constant currency terms and dragged down the infant, toddler, and preschool segment, which suffered an 11% sales decline. However, the Fisher-Price performance was better than the 15% plunge sales took last year, so it's possible the efforts the toy maker is making to rightsize the brand will pay off sooner rather than later.

Still, the complete recall of the Fisher-Price Rock 'n Play Sleeper caused a $4 million hit to sales, general, and administrative expenses that otherwise declined, and the company expects a loss of $30 million to $35 million in revenue this year related to the inclined sleep product.

But everything else is so much better

And that was mostly the extent of the bad news that Mattel had, and seemingly what prompted Wall Street's less optimistic view of the quarter. What analysts apparently didn't account for was just how well the rest of Mattel's portfolio was going to do.

Barbie sales surged 13% in currency-adjusted sales, helping the dolls segment grow 6%, while Hot Wheels was up 9%, leading to a 3% increase in vehicles sales after accounting for foreign currency exchange rates.

The big mover, though, was the action figures, building sets, and games division, which surged 23% on the strength of sales related to Disney's (DIS -1.18%) Toy Story 4 movie that was released in late June.

As I pointed out last week, Mattel was already hinting that sales were doing well ahead of the movie's box office debut, so despite its release late in the quarter, the film was bound to have an outsize impact. That was supported by a successful opening weekend, the biggest of any of the movies in the franchise; Toy Story 4 has earned over $873 million in worldwide receipts so far.

Chairman and CEO Ynon Kreiz pointed out that according to NPD Group data, Mattel's Toy Story action figures were the No. 1 selling action figures in the U.S. for each of the past eight weeks.

Ready to return to the playground

Equally important for Mattel's future is its announcement that it has already exceeded the $650 million in cost savings it had planned to achieve by the end of 2019, giving it a run rate of $754 million in savings. It now expects to realize another $100 million in savings in the back end of the year and is looking toward increasing the savings after that.

Mattel had been a damaged brand for some time, experiencing five years of falling sales. Desperate for a bailout, the company had even looked to rival Hasbro for help. While a buyout obviously didn't happen, Mattel seems to have fixed itself, and investors now have a much bigger, better, more financially secure toy maker that is looking at a brighter future.