In German, “er” could refer to a non-person or inanimate antecedent noun that has masculine grammatical gender, in which case “er” should be translated to “it”. “It” should definitely be accepted and might make more sense here, unless “fliegt auf einem Schmetterling” is a standard expression.
Shouldn't the accusative be used here as 'fliegt' shows movement?
No, because after two-way prepositions such as auf, the accusative is not used simply because there is movement involved; rather, it indicates the destination of a movement that starts somewhere else and ends at the noun following the preposition.
Er fliegt auf auf einen Schmetterling would mean "He is flying onto a butterfly" (i.e. he starts somewhere, flies a bit, and lands on the butterfly).
But Er fliegt auf einem Schmetterling (with the dative case) means "He is flying on a butterfly", i.e. the flying takes place while he is on the butterfly. The butterfly is the location of the flying.
For me the sentence meant that the person was flying on a butterfly (i.e. from one place to another).
That's how I understood it as well.
He was on the butterfly all the time while the flying took place -- so the butterfly was not the destination of the flying. The dative is appropriate.