Flash, _lockroot, Stage, and hitTest

April 3rd, 2007 by Andrew

While working on my portfolio project for my Flash class, I realized that _lockroot doesn’t help at all with Stage and hitTest when loading one SWF from another. I had to search around the Internet until I finally found something about _lockroot and hitTest on this guy’s blog. This is what I found to remedy the hitTest situation. This code overrides the hitTest function, and translates the coordinates to the global frame. It should go in the SWF that’s being imported.

MovieClip.prototype.oldHitTest = MovieClip.prototype.hitTest;
MovieClip.prototype.hitTest = function(x, y, sf){
	var obj = {x:x, y:y};
	this._parent.localToGlobal(obj);
	return this.oldHitTest(obj.x, obj.y, sf);
}

Warning: this still doesn’t work for the version of the hitTest function that takes in a MovieClip as its parameter. That’s that, and hopefully I won’t have that problem again.

Comments

There are no comments.

Leave a Reply