Topic: Game Programming /
AS3: Relative locations with movieclips and classes
Note: using ‘name’ (quotes) is just to show the exact name of the movie clip.
What I’m trying to do is have a movie clip with an instant name of ‘gun’ have it’s x value be the x value of ‘char’, plus the width of ‘char’.
I know this is a bit wrong, though I’m not sure what, these are the classes:
Game.as, Gun.as, Char.as
Game.as states that both gun and char are movieclips, and places them on the stage using addChild()
Char.as says: this.x = 200
(‘char’ is 50 pixels wide)
Gun.as says: this.x = char.x + char.width
(the part that’s wrong)
1120: Access of undefined property char.
The reason I can’t just do this.x = char.x + 50 is that the width changes. I might have other things incorrect besides just the Char.as, but I’m not sure.
I used the AS3 shootorial part 1 source, but changed some things around. If I delete the this.x= thing then everything is displayed, just not where I want them to be.