  We present a detailed analysis of the beam energy dependence of the
mechanisms for the generation of directed and elliptic flows in Au+Au
collisions focusing on the role of hadronic rescattering and spectator
shadowing within a microscopic transport model JAM with different equation of
state. A systematic study of the beam energy dependence is performed for Au+Au
collisions at $\sqrt{s_{NN}} =2.3 - 62.4$ GeV. The transition of the dynamical
origin of the directed flow is observed. We find that the initial Glauber type
nucleon-nucleon collisions generate negative $v_1$ for nucleons at midrapidity
due to the presence of spectator matter, and this negative nucleon $v_1$ is
turned to be positive by the meson-baryon interactions at the beam energy
region of $\sqrt{s_{NN}} < 30$ GeV. In contrast, above 30 GeV there is no
spectator shadowing at midrapidity, and initial nucleon-nucleon collisions do
not generate directed flow, but subsequent rescatterings among produced
particles generate negative $v_1$ for nucleons. It is demonstrated that
negative pion-directed flows are mostly generated by the interaction with the
spectator matter. It is also shown that the squeeze-out effect is largely
suppressed in the case of softening, which leads to the enhancement of elliptic
flow around $\sqrt{s_{NN}}=5-7$ GeV. The elliptic flow at midrapidity above 10
GeV is not influenced by the squeeze-out due to spectator matter, while its
effect is seen at the forward rapidity range of $y/y_\mathrm{c.m.}>0.5$, which
decreases as beam energy increases.
