Hey all, This one is going to take some setup, so bear with me,
I have built an actionscript file to be used as a class library (i think that is what i would call it), it looks like this:
class Effects extends MovieClip {
var this_mc:MovieClip;
var Dx:Number = 0;
var Dy:Number = 0;
var Px:Number = 0;
var Py:Number = 0;
public function Effects(passed_mc:MovieClip) {
this_mc = passed_mc;
}
function mouseFollow(centerx:Object, centery:Object, inertia:Number, k:Number) {
Dx = -this_mc._x+centerx;
Dy = -this_mc._y+centery;
Px = Px*inertia+Dx*k;
Py = Py*inertia+Dy*k;
this_mc._x += Px;
this_mc._y += Py;
}
}
A not so simple chunk of code that i use to create a “mouse follow” effect when it is used.
Speaking of, i use
var LINE:Effects = new Effects(lineA);
//
_root.onEnterFrame = function(){
LINE.mouseFollow(_root._xmouse, 0, .7, .9);
}
to reffer to the code above. Everything works up to this point.
Trouble is when i try to use the code on more than one object on the stage. I have code that listens for keyboard input and when you press a certain key it creates and new blank movie and then loads the appropriate content for that key. It looks like this
createEmptyMovieClip("collage", 1);
createEmptyMovieClip("const", 2);
var k:Number;
k = 1;
//
keyLoad = function (key) {
//trace ("key load activated");
//trace ("key pressed is : " + key);
collage_holder.attachMovie("anim"+key, "a"+(k++), k);
collage_holder["a"+(k-5)].removeMovieClip();
};
That is to say, when i press a key on the keyboard once, the loaded movie follows the mouse. But when i press the same key again, the first loaded movie stops, and the new one loaded follows the mouse. What happens.
I should note that when i use and #include to call the same chunk of code, the problem vanishes.
Thoughts?