ForumsProgramming Forumneeding help on creating objects like guns shooting bullets

3 1567
stijnhero
offline
stijnhero
22 posts
125

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

  • 3 Replies
strouthas
offline
strouthas
24 posts
30

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

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

manny6574
offline
manny6574
923 posts
200

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();

}

manny6574
offline
manny6574
923 posts
200

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

Showing 1-3 of 3