Hey guys,
So in my game, I have these turrets. And to get them to fire I have to attach bullets to the stage. To do this I need to find the global coordinates of the turrets cause they are nested in another movieclip. So I came up with this:
function globalCoordinate(object:MovieClip, type:String):Number {
var point:Object = {x:object._x,y:object._y};
object._parent.localToGlobal(point)
if (type == "x") {
return(point.x);
}
else {
return(point.y);
}
}
This works perfectly for direct movieclip parameters. What I want is for the turret to be activated and to pass on itself to the function that shoots it. Example:
onClipEvent(enterFrame) {
_root.Shoot(this);
}
So now the function is in the root of the timeline:
function Shoot(turret:Movieclip) {
}
Here is were the difficulty begins. I have the turret passed down onto the function. But I cant tell the function to do this:
function Shoot(turret:Movieclip) {
trace(globalCoordinate(turret, "x"))
}
I get "undefined". I think this is because turret isnt a direct movieclip, or because when I trace "turret" from the function Shoot I get "Level0.etc.etc.turret1". Could the level0 be interfering. I tried converting it to a string and getting rid of the level 0 part but now i dunno how to get it back into MovieClip form.
PLEASE PLEASE PLEASE HELP!!!! Also, the code above is not buggy. Maybe I typed it in wrong but that shouldnt be the problem.