PDA

View Full Version : Access of undefined property parent



Alpha Remex
November 12th, 2009, 12:08 PM
Hey guys - can't figure out why "parent" would be an undefined property.. this is a compiler error, not run-time:



override protected function fire():void {

var startX:Number = MovieClip(parent).x + (MovieClip(parent).width/2);
var startY:Number = MovieClip(parent).y + (MovieClip(parent).height/2);

var bullet:Bullet = new BlasterBullet(_stage, startX, startY, _firingSpeed, _firingStrength);
}

creatify
November 12th, 2009, 12:36 PM
What does your class extend? I think we'd need more context to figure it out. Could the parent be a sprite? And does this always exist on the displayList of another object - not that that matter if it's compiler error. it could be an error some other place as well and is just throwing on that line for some reason.

micken
November 12th, 2009, 12:58 PM
parent would be an undefined property if the class does not extend DisplayObject

Alpha Remex
November 12th, 2009, 03:52 PM
parent would be an undefined property if the class does not extend DisplayObject

you're right!

Good call!