Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Another shot...using interval to move something...

Status
Not open for further replies.

fedtrain

Instructor
Jun 23, 2004
142
US
Ok a second shot at this.

I need to set up an interval..then I need to use that interval to move a movieclip across the screen to a set x coordinate. I am using the interval because a straight for loop doesn't scroll...it just jumps.

Here is the button code:
Code:
btMove.onRelease = function(){
	moveMovie(200,1,5);
}
btMove2.onRelease = function (){
	moveMovie (200,2,5);
}

Here is the function that is called:
Code:
function moveMovie (r,o,c){
  var q:Number = (this["mcBox"+o]._x);
  var m:Number = (q - r);
//this will set an interval to slide the movie along
  var myInterval = setInterval (moveSlowly, 100)
     function moveSlowly(){
	trace (this["mcBox"+o]._x);
	if (this["mcBox"+o]._x >= r){
		q -= c;
		this["mcBox"+o]._x = q;
		updateAfterEvent();
	}
	else if (["mcBox"+o]._x <= r){
		q += c;
		this["mcBox"+o]._x = q;
		trace (q);
	}
	else {
		clearInterval (myInterval);
	}
     }
}

Kenneth has tried to help in another thread, but I can't get his code to work at all on my Flash 8...it just does nothing...not even an error.

I have continued to struggle with this for more days that I wish to admit, and this functionality will end up in a project for work...and I really really need to move on to the sounds and get this done.

In the above code I have two functions...I can trace all the variables from the first in the second...no problem, but the minute I try to use the ["mcBox"+o]._x....I get undefined. I need that number!!!

Actually, I can even trace (this["mcBox+o"])...that works. But the minute I try to get the x coord...it dies.

GAH!!!!!

Please save me!

Dave

"Credit belongs to the man who is actually in the arena - T.Roosevelt
 
If you are trying to animate movement across the stage, have you looked at using the Tween class? 3 main parameters of this would be:
1. what tween should be applied to (ie: _x, _y, _alpha, ...etc)

2. start value, end value (ie: _x starts at 0, ends at 50)

3. Time it takes, either in frames or seconds (Maybe its milliseconds)

Anyways, its pretty easy to use, and here is a link that has a couple of examples and explanation (Flash 8): Using the Tween class
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top