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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

movieClips not working how I want

Status
Not open for further replies.

dlacloche

Programmer
Oct 9, 2006
1
US
As a motion graphic artist who's been working with keyframes forever, it's really blowing my mind that you can create cool animation with just code. Being new to this concept, I can't figure out how to get this to happen:

onRelease, movieClip1 (where ever it happens to be at the time of click) travels to x=150, y=60 of the stage. And the other movieClips--movieClip2, movieClip3, movieClip4, and movieClip5 move to the left side of the stage, x=75 y=200, 250, 300, and 350 respectively.

And of course, I want the same to happen to the other movieClips--when you click on them they go to x=150, y=60 and the others go off to the side.

I have some ActionScript that works on the first click of any movieClip, but if you click any movieClip after that, all the movieClips gravitate to eachother. The more you click the closer they get, until they're all overlapping and jittering around a little.

I'm new at all this, and I need help. Thanks.
Here's the code:

var startX2 =_root.ball2._x
var startY2 =_root.ball2._y
var startX1 =_root.ball1._x
var startY1 =_root.ball1._y
var startX3 =_root.ball3._x
var startY3 =_root.ball3._y
var startX4 =_root.ball4._x
var startY4 =_root.ball4._y
var startX5 =_root.ball5._x
var startY5 =_root.ball5._y
var endX1 = 75
var endY1 = 200
var endX2 = 150
var endY2 = 250
var endY3 = 300
var endY4 = 350
var endY5 = 400
var endY6 = 60

var speed = 10
ball2._x = startX2
ball2._y = startY2
ball1._x = startX1
ball1._y = startY1
ball3._x = startX3
ball3._y = startY3
ball4._x = startX4
ball4._y = startY4
ball5._x = startX5
ball5._y = startY5
function moveMe2(targ){
targ._x+=(_root.endX1-targ._x)/_root.speed;
targ._y+=(_root.endY1-targ._y)/_root.speed
}
function moveMe1(targ){
targ._x+=(_root.endX2-targ._x)/_root.speed;
targ._y+=(_root.endY6-targ._y)/_root.speed
}
function moveMe3(targ){
targ._x+=(_root.endX1-targ._x)/_root.speed;
targ._y+=(_root.endY2-targ._y)/_root.speed
}
function moveMe4(targ){
targ._x+=(_root.endX1-targ._x)/_root.speed;
targ._y+=(_root.endY3-targ._y)/_root.speed
}
function moveMe5(targ){
targ._x+=(_root.endX1-targ._x)/_root.speed;
targ._y+=(_root.endY4-targ._y)/_root.speed
}

stop();


ball1.onRollOver = function () {
this.reverser_mc.gotoAndStop(1);
this.play(1);
}

ball1.onRollOut = function () {
this.reverser_mc.gotoAndPlay(2);
}

ball1.onPress = function () {
this.gotoAndStop(15);
}

ball1.onRelease = function () {
this.gotoAndStop(1);
}
ball1.onRelease = function () {
setInterval(moveMe1,30,_root.ball1);
setInterval(moveMe2,30,_root.ball2);
setInterval(moveMe3,30,_root.ball3);
setInterval(moveMe4,30,_root.ball4);
setInterval(moveMe5,30,_root.ball5);
}

ball2.onRollOver = function () {
this.reverser_mc.gotoAndStop(1);
this.play(1);
}

ball2.onRollOut = function () {
this.reverser_mc.gotoAndPlay(2);
}

ball2.onPress = function () {
this.gotoAndStop(15);
}

ball2.onRelease = function () {
setInterval(moveMe1,30,_root.ball2);
setInterval(moveMe2,30,_root.ball3);
setInterval(moveMe3,30,_root.ball4);
setInterval(moveMe4,30,_root.ball5);
setInterval(moveMe5,30,_root.ball1);
}


ball3.onRollOver = function () {
this.reverser_mc.gotoAndStop(1);
this.play(1);
}

ball3.onRollOut = function () {
this.reverser_mc.gotoAndPlay(2);
}

ball3.onPress = function () {
this.gotoAndStop(15);
}

ball3.onRelease = function () {
setInterval(moveMe1,30,_root.ball3);
setInterval(moveMe2,30,_root.ball4);
setInterval(moveMe3,30,_root.ball5);
setInterval(moveMe4,30,_root.ball1);
setInterval(moveMe5,30,_root.ball2);
}


ball4.onRollOver = function () {
this.reverser_mc.gotoAndStop(1);
this.play(1);
}

ball4.onRollOut = function () {
this.reverser_mc.gotoAndPlay(2);
}

ball4.onPress = function () {
this.gotoAndStop(15);
}

ball4.onRelease = function () {
setInterval(moveMe1,30,_root.ball4);
setInterval(moveMe2,30,_root.ball5);
setInterval(moveMe3,30,_root.ball1);
setInterval(moveMe4,30,_root.ball2);
setInterval(moveMe5,30,_root.ball3);
}


ball5.onRollOver = function () {
this.reverser_mc.gotoAndStop(1);
this.play(1);
}

ball5.onRollOut = function () {
this.reverser_mc.gotoAndPlay(2);
}

ball5.onPress = function () {
this.gotoAndStop(15);
}

ball5.onRelease = function () {
setInterval(moveMe1,30,_root.ball5);
setInterval(moveMe2,30,_root.ball1);
setInterval(moveMe3,30,_root.ball2);
setInterval(moveMe4,30,_root.ball3);
setInterval(moveMe5,30,_root.ball4);
}
 
I hope I understood you correctly!
Code:
// AS2 main timeline
var speed:Number = 10;
var arrBall:Array = new Array();
for (var i = 1; i<=5; i++) {
	arrBall.push("ball"+i);
}
var arrTarget:Array = [[150, 60], [75, 200], [75, 250], [75, 300], [75, 350]];
this.onEnterFrame = function():Void  {
	for (var s in arrBall) {
		var ballMC:MovieClip = this[arrBall[s]];
		with (ballMC) {
			_x += (ballMC.targetPos[0]-_x)/speed;
			_y += (ballMC.targetPos[1]-_y)/speed;
		}
	}
};
for (var s in arrBall) {
	var ballMC:MovieClip = this[arrBall[s]];
	ballMC.onRelease = function():Void  {
		this["targetPos"] = arrTarget[0];
		var index:Number = 1;
		for (var i = 0, n = arrBall.length; i<n; i++) {
			var mc:MovieClip = this._parent[arrBall[i]];
			if (mc != this) {
				mc["targetPos"] = arrTarget[index];
				index++;
			}
		}
	};
}
stop();

Kenneth Kawamoto
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top