PDA

View Full Version : [FMX] Hittest and functions



tgelston
April 18th, 2003, 12:41 PM
I have a problem running a hitTest on a duplicated object - it doesnt work.

Here is what I have so far, all of this code is in the onload of a movie that is just holding my code-

//Makes the rocks
function dupRockFunction() {
var chance = Math.round(random(25));
if (chance == 11) {
rockdepth++;
_root.spaceRock = this.duplicateMovieClip("_root.rock"+rockdepth, rockdepth);
_root.spaceRock._y = random(400);
_root.spaceRock._xscale = random(50)+30;
_root.spaceRock._yscale = _root.spaceRock._xscale;
_root.spaceRock._rotation = random(360);
}
//Moves the rocks
function moveRemoveRockFunction() {
//moves clip to left
this._x -= rockSpeed;
//removes clip when off stage
if (this._x<20) {
this.removeMovieClip();
}
if (this.hitTest(_root.ship)) {
trace("Hello");
}
}


I call both functions in the enterframe section of the same MC

_root.spaceRock.onEnterFrame = moveRemoveRockFunction;
_root.rock.onEnterFrame = dupRockFunction;


Why doesnt that hittest work? if "this" works to move them across the stage why doesnt it also see the contact of the two MCs??

I am new to functions - slowly learning so if you see anything else major I should change please let me know.

Thanks,
T

senocular
April 18th, 2003, 12:48 PM
... is that moveRemoveRockFunction inside dupRockFunction? is that what you wanted? and where are
_root.spaceRock.onEnterFrame = moveRemoveRockFunction;
_root.rock.onEnterFrame = dupRockFunction;
?
They arent in the onClipEvent(enterframe) are they?
And do you know duplicated clips keep all functions attached?
also in the name part of duplicate movie, you dont need to specify _root. - just the name

At first glance Im having a little trouble seeing the setup of this. a file would be nice :)

tgelston
April 18th, 2003, 01:23 PM
... is that moveRemoveRockFunction inside dupRockFunction? is that what you wanted?
NO they should not be inside each other - I dont think they are.



and where are
_root.spaceRock.onEnterFrame = moveRemoveRockFunction;
_root.rock.onEnterFrame = dupRockFunction;?
They arent in the onClipEvent(enterframe) are they?
all of the code I pasted is sitting on a MC - the function section is in the onload and the function calling:
_root.spaceRock.onEnterFrame = moveRemoveRockFunction;
_root.rock.onEnterFrame = dupRockFunction;
is in the enterframe section of the same clip - is that bad? I could not get it to work if I stuck it in the first frame of the game scene


And do you know duplicated clips keep all functions attached?Yes. . . I think so - does my code not reflect that? That is why I expect the hitTest to work - using this. moves the object but it wont see the hitTest.

I need to add: all the code referenced is on the blue circle left of stage. Thanks
Download the Fla (http://www.mcps.k12.md.us/schools/watkinsmillhs/rock_attack_scroller.fla) (sorry it 330Kb)

Thanks for looking,
Tobias

tgelston
April 19th, 2003, 07:36 AM
this was my problem, senocular, pointed it out but I ignored him becuase everything else worked. I would love it if someone could explain why it dupicates correctly with _root. there but will not do the hitTest correctly?

_root.spaceRock = this.duplicateMovieClip("_root.rock"+rockdepth, rockdepth);


should be

_root.spaceRock = this.duplicateMovieClip("rock"+rockdepth, rockdepth);


no _root in front of "rock"

just sharing!
Tobias

eyezberg
April 19th, 2003, 08:54 AM
for function dupRockFunction the closing } is missing, that's why sen asked about the nesting, 1st } closes the if only..
"_root.rock" or "rock" +rockdepth will be the instance name of the duplicated clip, so it's not the same..