I’ve got this mc that moves left and right when the arrows are pressed, and what i need to do is that once the mc gets to a certain position, it will gotoAndPlay an animation within it.
I tried using hitTest to begin with, but that wasnt working. Am i doing it the easy way of not using hitTest?
Replace movieClip with the instance name of your movieClip, and theXYouWantToTestHere and theYYouWantToTestHere with the X and Y positions of where you want to see if the movieClip is hitting
Put this on the frame of the movie (not the movieClip itself)
I tried out what you suggested, and it looked as if it would work, but, sadly, it didn’t.
Did you try out the code you just gave me on my fla, and if so, did it work for you?
oh yeah… dint think it thru entirely… :S sorry!
this works…
var speed = 5;
var min = -5
var max=150
blob.onEnterFrame = function() {
if(this._x>=max){
if (Key.isDown(Key.LEFT)) {
this._x -= speed;
this.gotoAndStop("left");
}
}
else if(this._x<=min){
if (Key.isDown(Key.RIGHT)) {
this._x += speed;
this.gotoAndStop("right");
}
}
else{
if (Key.isDown(Key.RIGHT)) {
this._x += speed;
this.gotoAndStop("right");
}
if (Key.isDown(Key.LEFT)) {
this._x -= speed;
this.gotoAndStop("left");
}
}
if (this.hitTest(tree)) {
this.gotoAndPlay("anim");
delete this.onEnterFrame;
}
}
or you could use a slightly shorterhand:
var speed = 5
var min = -5
var max=150
var right = true
var left = true
blob.onEnterFrame = function() {
if(this._x>=max){
right = false
left = true
}
if(this._x<=min){
left = false
right = true
}
if(right == true){
if (Key.isDown(Key.RIGHT)) {
this._x += speed
this.gotoAndStop("right")
}
}
if(left == true){
if (Key.isDown(Key.LEFT)) {
this._x -= speed
this.gotoAndStop("left")
}
}
if (this.hitTest(tree)) {
this.gotoAndPlay("anim")
delete this.onEnterFrame
}
}
or im waiting for someone to swoop in and use an even better method lol
but i hav an excuse atm - iv got a headache (cue sympathy… or lack of…) lol ciao4now!
Prophet.
EDIT:- btw u thinking of easing that movement or leaving it be?