how I can play online on virtual console games?
Well, you can, but not for real. You have to use infrared and local wi-fi to trade/battle with someone (meaning you must be right next to the person you're trading/battling with). The video right here should demonstrate how to do these things. That video only covers RBY but I'm pretty sure it's the same for GSC.