Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

_name of hitTest() clips

Status
Not open for further replies.

XLax

Technical User
May 22, 2006
25
CA
I've been trying to find a way to find the _name property of a movie clip a certain other movie clip is collided against but can't. Does anybody know?
 
I'm trying to find a way so that instead of telling me if the hitTest is true or false, it tells me what movie clip is colliding with my main movie clip.
 
1. Workout the area classifies as collision. For example, if a MovieClip is within the area within TargetMovieClip location plus/minus 50px it classifies as collision.

2. Go through all the MovieClips on Stage and check if the location is within the area defined.

If I express above in AS it would be:

[tt]// main timeline
onEnterFrame = function ():Void {
for (var s in this) {
if (typeof (this) == "movieclip") {
if (s != "mcTarget") {
if (this._x>mcTarget._x-50) {
if (this._x<mcTarget._x+50) {
if (this._y>mcTarget._y-50) {
if (this._y<mcTarget._y+50) {
trace(s+" is collided with mcTarget!");
}
}
}
}
}
}
}
};
//[/tt]

Kenneth Kawamoto
 
I am getting this error message:

// in output window
Symbol=Game, Layer=Play, Frame=1: Line 1: '{' expected
onEnterFrame = function ():Void {

Symbol=Game, Layer=Play, Frame=1: Line 17: Unexpected '}' encountered
};
//
 
Can you explain what your script is saying line by line?
 
//Run this script on every frame refresh

onEnterFrame = function (){

//Go through every object in "this" (_root) using "s" as iterant variable

for (var s in this) {

//Is the iterant object MovieClip?

if (typeof (this) == "movieclip") {

//...and it's not "mcTarget"?

if (s != "mcTarget") {

//...and its xy position is within +/-50px of mcTarget?

if (this._x>mcTarget._x-50) {
if (this._x<mcTarget._x+50) {
if (this._y>mcTarget._y-50) {
if (this._y<mcTarget._y+50) {

//...if so then the iterant is collided with mcTarget!

trace(s+" is collided with mcTarget!");

Kenneth Kawamoto
 
Kenneth, you're a genius.
 
Oh one more thing
//
function detectCollision(what) {
for (var s in this) {
if (typeof (this) == "movieclip") {
if (s != what) {
if (this._x>what._x-50) {
if (this._x<what._x+50) {
if (this._y>what._y-50) {
if (this._y<what._y+50) {
trace(s+" is touching");
}
}
}
}
}
}
}
}
onEnterFrame = function () {
detectCollision("player");
};
//
I have that, and it keeps tracing "instance3 is touching"
Do you know why?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top