hi friends,
i have a problem with this code. when i run this code, i want that the arrow should not accross the wall movieclip but it is accrossing the wall.
So if anyone have some idea about what we can do for to get the desired result.
thaks
my FLA file code:
var myclass:moveArray = new moveArray(arrow_mc);
As files code:
class moveArray extends MovieClip {
var targetMc:MovieClip;
var mc:MovieClip;
var wall:MovieClip;
//var myListener:addEventListener;
public function moveArray(targetMc:MovieClip) {
//trace(targetMc);
this.targetMc = targetMc;
checkPosition(targetMc);
updatePosition(targetMc);
}
//-------------------------------------------------------------------
public function updatePosition(mc:MovieClip) {
var myListener:Object = new Object();
myListener.onKeyDown = function() {
if (Key.isDown(Key.RIGHT)) {
//trace("right key is pressed");
//trace(mc);
mc._rotation = 90;
mc._x += 25;
}
if (Key.isDown(Key.LEFT)) {
//trace("left key is pressed");
mc._rotation = -90;
mc._x -= 25;
}
if (Key.isDown(Key.UP)) {
//trace("up key is pressed");
mc._rotation = 360;
mc._y -= 25;
}
if (Key.isDown(Key.DOWN)) {
//trace("down key is pressed");
mc._rotation = 180;
mc._y += 25;
}
};
Key.addListener(myListener);
}
//------------------------------------------------------------
public function checkPosition(mc:MovieClip) {
mc.onEnterFrame = function() {
if (this._x>=Stage.width) {
//trace("right");
this._x = Stage.width-this._height/2;
}
if (this._x<=0) {
this._x = this._height/2;
}
if (this._y<=0) {
this._y = this._height/2;
}
if (this._y>=Stage.height) {
this._y = Stage.height-this._height/2;
}
};
}
public function chkcoll(mc:MovieClip, obj:Object) {
if (mc.hitTest(obj)) {
// this._y = 249;
}
}
}