Forums

ForumsProgramming Forum

needing help on creating objects like guns shooting bullets

Posted May 20, '12 at 8:54am

stijnhero

stijnhero

22 posts

hey i've been doing some as3 and i can't find the code on how to create an object on clicking eg. please help me! thanks

 

Posted May 20, '12 at 2:04pm

strouthas

strouthas

24 posts

assuming you have a linkage with id Bullet in your library, you can instantiate it with:

var bullet:Bullet = new Bullet();
addChild(bullet);

 

Posted May 20, '12 at 6:00pm

manny6574

manny6574

862 posts

first add an event listener to the stage(or whatever it is to be clicked)which listens for a MouseEvent.CLICK, then make the event handler function. in this function:

function createBullet(e:Event){
    var bullet:Bullet = new Bullet();

}

 

Posted May 20, '12 at 6:06pm

manny6574

manny6574

862 posts

oops

function createBullet(e:MouseEvent){

    var bullet:Bullet = new Bullet();
    bullet.x = mouseX ;
    bullet.y = mouseY;
    addChild(bullet)

}

this would create a Bullet on the position of the mouse, when you click. you can replace mouseX and Y with whatever you want

 
Reply to needing help on creating objects like guns shooting bullets

You must be logged in to post a reply!