The spider did not fly. Here is what happened:
Harry Potter and the Goblet of Fire, Chapter 14: The Unforgiveable Curses
Moody reached into the jar, caught one of the spiders, and held it in the palm of his hand so that they could all see it. He then pointed his wand at it and muttered, “Imperio!”
The spider leapt from Moody’s hand on a fine thread of silk and began to swing backward and forward as though on a trapeze. It stretched out its legs rigidly, then did a back flip, breaking the thread and landing on the desk, where it began to cartwheel in circles. Moody jerked his wand, and the spider rose onto two of its hind legs and went into what was unmistakably a tap dance.
The Imperius Curse gives the caster complete control over the mind of the victim. It allowed Moody to make the spider perform acrobatics using its silk thread, but not fly. It's as if the victim has no mind and just performs what it's told to do by the controller, without thinking whether it can do that or not, as is described later when fake-Moody puts the curse on students.
Harry Potter and the Goblet of Fire, Chapter 15: Beauxbatons and Durmstrang
Moody began to beckon students forward in turn and put the Imperius Curse upon them. Harry watched as, one by one, his classmates did the most extraordinary things under its influence. Dean Thomas hopped three times around the room, singing the national anthem. Lavender Brown imitated a squirrel. Neville performed a series of quite astonishing gymnastics he would certainly not have been capable of in his normal state. Not one of them seemed to be able to fight off the curse, and each of them recovered only when Moody had removed it.