I am trying to perform a hit test with movie clips through linkage properties. What I have is images (panes) that rotate in a circle and I want to give the user the ability to zoom in / out of the panes when they cross a certain area of the stage. I created a movie clip (“test”) that would come in contact with the panes so that all the images would not zoom just the corresponding pane in contact with “test”. I figured using a hit test would solve this problem but I am open to any other way I could do this. The problem action script is marked with stars *******.
// create a scene movieclip to contain all 3D elements
// and center it on the screen.
this.createEmptyMovieClip("theScene", 1);
theScene._x = 150;
theScene._y = 100;
// now we'r going to create an array to keep track of all the
// objects in the scene. That way, to position all the objects
// you just need to loop through this array.
objectsInScene = new Array();
// no camera, but a rotation will be needed to keep track of the
// spinning involved (though its the same as the camera)
spin = 0;
// focal length to determine perspective scaling
focalLength = 500;
// the function for controling the position of a friend
displayPane = function(){
var angle = this.angle - spin;
var x = Math.cos(angle)*this.radius;
var z = Math.sin(angle)*this.radius;
var y = this.y;
var scaleRatio = focalLength/(focalLength + z);
this._x = x * scaleRatio;
this._y = y * scaleRatio;
this._xscale = this._yscale = 100 * scaleRatio;
// on top of the normal scaling, also squish the
// _xscale based on where in the rotation the pane is
// since you would be looking at its side when at a z
// of 0, it would be at its thinnest which would be
// 0 since its a completely flat pane. So for that,
// we can use the trig function of z (sin) to squish the
// _xscale based on its position in z.
this._xscale *= Math.sin(angle);
this.swapDepths(Math.round(-z));
}
// attach each pane in a loop and arrange them in a
// circle based on the circumference of the circle
// divided into steps
angleStep = 2*Math.PI/10;
for (i=0; i < 10; i++){
attachedObj = theScene.attachMovie("pane" + i, "pane"+i, i);
attachedObj.angle = angleStep * i;
attachedObj.radius = 200;
attachedObj.x = Math.cos(attachedObj.angle) * attachedObj.radius;
attachedObj.z = Math.sin(attachedObj.angle) * attachedObj.radius;
attachedObj.y = 40;
attachedObj.display = displayPane;
objectsInScene.push(attachedObj);
}
panCamera = function(){
// rotate camera based on the position of the mouse
spin -= (Key.isDown(Key.RIGHT))/10;
spin += (Key.isDown(Key.LEFT))/10;
// Now, with the camera spun, you need to perform the rotation
// of the camera's position to everything else in the scene
for (var i=0; i<objectsInScene.length; i++){
objectsInScene*.display();
}
};
*******************************************
theScene.onEnterFrame = function() {
if ("pane"+i.hitTest(test) && Key.isDown(Key.UP)&& this._width < 110 && this._height < 110) {
this._width *= 1.3;
this._height *= 1.3;
}
else if (Key.isDown(Key.DOWN) && this._width > 45 && this._height > 45) {
this._width /= 1.3;
this._height /= 1.3;
}
};
***********************************************
// make each figure run backAndForth every frame
theScene.onEnterFrame = panCamera;