Next to the menu I have a movieclip (instance name “square”) which I want to appear on the stage from the left, but not before menu (see above) has reached it’s final position. How do I integrate this in the above function or should I make a seperate function for this :q:
You’ve got a little syntax error in there The operator to check for equality (==**) is not equal to the assignment operator. So you would have to change if (this._y = yPos) to if (this._y == yPos). Here’s my solution for this (a different way).
Thanks for your solution. The ProtoType is indeed a good solution. I still have one question about my own function. I changed the = in == so my code looks like this:
[AS]function moveMenu (clip, yPos, speed){
clip.onEnterFrame=function(){
var endyPos = yPos-this._y;
this._y += endyPos/speed;
if (this._y == yPos) {
function moveSquare (clip2, xPos, speed){
clip2.onEnterFrame=function(){
var endxPos = xPos-this._x;
this._x += endxPos/speed;
Well, first of all, youare checking if y is equal to the position to move to. But, since you are always dividing by 3, there is a chance that the position won’t be exactly the same as the target. Therefore, I always check if the position is inside a range of 2px from the target:
if(this._y > endyPos-1 && this._y < endyPos+1)
Using this code, there is a chance that the position of the movieclip is at max 1px off it’s target, but I don’t that’s really important; after all, who’s gonna notice 1px ?
Secondly, you have an error in how it works. When the movieclip has reached it’s position, you keep declaring the function but not calling. You must call the function, not declare it. You are already calling it at the beginning:
But it hasn’t been defined yet because the first movieclip hasn’t reached it’s target yet, and it’s declared when the target is reached. This is absolutely wrong. Also, you should delete the first onEnterFrame when it has reached it’s target.