More than 40 middle schools participating in Mayor Bill de Blasio’s new after-school initiative have learned they will have to cancel their upcoming summer programs, just months after being told that funding would be available.

The money, a city official said in an email to after-school program directors last week, was being “re-directed to schools with the greatest challenges.” The news came days after de Blasio announced that he was pumping an extra $50 million of city and state money into 130 struggling schools, including the 94 in his administration’s turnaround program.

Now, the middle schools need to make other plans.

“What can I say?” said Principal Ron Link of Theatre Arts Production Company School in the Bronx, who got the news on Wednesday afternoon. “That’s the nature of the principal’s job. You get constant news out of left field.”

The summer program would have been an extension of the mayor’s new after-school initiative for middle-schoolers, called School’s Out New York City, which has programs in more than 560 schools this year. Directors of those middle-school programs were told in a February email that the city was “excited” that funding had become available for the summer. By the end of March, a few dozen programs had been given the green light to start up again in July for at least four weeks.

But an official told program directors in an email on May 8 that while overall funding for the after-school programs had increased, “some of the City’s planned summer funding will be re-directed.”

“We are unable to expand summer services as previously proposed,” wrote Mike Dogan, assistant commissioner of the Department of Youth and Community Development.

Advocates are concerned that other, established programs that serve students over the summer will also see funding reductions under the mayor’s latest spending plan, including Beacon community centers and the Cornerstone programs that operate in public housing. The Campaign for Children, a 150-member coalition of early education and after-school groups that include the Children’s Aid Society and the Citizens’ Committee for Children of New York, estimated Wednesday that the changes to the three programs will affect 17,000 students.

“Programs are really quite frankly in a panic,” said Citizens’ Committee for Children executive director Jennifer March.

Dayana Perez, a spokeswoman for the Department of Youth and Community Development, said in statement that the city is still funding middle-school summer programs that existed before this year’s after-school expansion, including Beacon and Cornerstone programs in the city’s highest-needs communities, and that the Department of Education is continuing Summer Quest and its own arts- and STEM-focused summer programs. Officials said the city is budgeting for 39,000 summer program seats for elementary schoolers and 17,000 for middle-schoolers.

“The executive budget ensures that much-needed services are available to high-need students at 130 struggling schools,” Perez said. “This administration has made afterschool expansion a priority, and we will continue to work to make comprehensive afterschool opportunities available to all students.”

Still, the Campaign for Children estimates that it would cost at least $10.2 million to make the proposed middle-school summer programs a reality and boost funding at the Beacon sites and Cornerstone programs to their expected levels. And though the City Council has historically stepped in to fill gaps in after-school funding, March said any emergency funding included in a budget adopted in June likely wouldn’t come fast enough.

“Parents aren’t going to wait until June 30 to figure out what they’re doing with their kids the following week,” March said.

Geoff Decker contributed reporting.