First I'm kinda new to flash so I don't know if this is ok to ask =p.
Here it goes:
I'm having a problem to make my character move and his weapon follow the mouse while in movement. I have no problem when I dont put the gun inside the movie clip(the hero) and make a stage.addChild(..) instead of Hero.addChild(..). I'm using AS3 and using classes. I think the code will explain better.
//The class of the Pistol public class Pistol extends Weapon { private var angleBetweenMousePistol:Number; private var radianToDegree = (180/Math.PI); public function Pistol() { addEventListener(Event.ENTER_FRAME, eFrame); x = 55; y = 10; } public function eFrame(e:Event):void { angleBetweenMousePistol = Math.atan2(stage.mouseY - this.y, stage.mouseX - this.x ); angleBetweenMousePistol *= radianToDegree; this.rotation = angleBetweenMousePistol; } }
What I do next is create a hero using the Hero class and make the hero add the pistol
//class Main var hero:Hero = new Hero(); var pistol:Pistol = new Pistol(); hero.addChild(pistol); //
The problem is that everything happens like if the pistol movie clip have been added by the stage (it follows the mouse, but it acts like it'd be at its position I set earlier ( x = 55 and y = 10). I think this is a bit weird because it moves along the hero, but acts like if it weren't moving. Thanks to all.
Can't help you with that, sorry... I know a bit about AS3, but hardly everything I often do what I know works, and if I learn something new I try to update it in the code I'm using