I have done this exact transit twice on two AONEx's, going from AA to CX. If I recall correctly, the CX flights were booked on AA flight numbers with no problems.
In other words, it does work. However, note that you'll want to allow a good amount of time for the connection, because you do need to clear immigration, go through arrivals and to departures again, etc.
Speaking of immigration, the line/queue can be long (on one of transits I waited a full hour, though the other was just 15 minutes). There is a pathway to skip immigration and transfer directly, but on both visits I asked and was told that I needed to complete the full process.
The night flight is short and you'll probably arrive JFK bleary-eyed, but hey, it's CX First.
Have fun!