movieClips don't function right after they touch or overlap

  • dlacloche
  • Born
  • Born
  • dlacloche
  • Posts: 2
  • Loc: Madison, WI

Post 3+ Months Ago

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);
}
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

what if i tell you that i can simplify your code and also make it work as you wish?
ok ... this is an exception, i dont usually do this, but for the sake of good programming:
Code: [ Select ]
// variable declaration
var startX:Array = new Array();
var startY:Array = new Array();

var endX:Array = new Array(75, 150);
var endY:Array = new Array(200, 250, 300, 350, 400);

var arrIntervals:Array = new Array();

var g_nBallCount:Number = 5;
var iIndex:Number;
var speed:Number = 10;
var g_bMove = false;
var g_nIntervalIndex:Number = 0;


// functions
function moveMe(targ, id)
{
    var nX:Number = 0;
    var nTolerance = 0.5;
    if (targ.nID == id)
        nX = endX[1];
    else
        nX = endX[0];
        
    nY = endY[targ.nID - 1];
    
    targ._x+=(nX-targ._x)/_root.speed;
    targ._y+=(nY-targ._y)/_root.speed;
    
    if (targ._y - nTolerance <= nY && targ._y + nTolerance >= nY)
        targ._y = nY;
    if (targ._x - nTolerance <= nX && targ._x + nTolerance >= nX)
        targ._x = nX;
        
    if (targ._y == nY && targ._x == nX)
    {
        clearInterval(arrIntervals[targ.nID - 1]);
        g_nIntervalIndex++;
        if (g_nIntervalIndex == g_nBallCount)
        {
            g_bMove = false;
            g_nIntervalIndex = 0;
        }
    }
}

function SetBallIntervals(id)
{
    if (!g_bMove)
    {
        var nID:Number = id;
        var iIndex:Number = 0;
        while (iIndex < g_nBallCount)
        {                
            arrIntervals[nID - 1] = setInterval(moveMe,30,this["ball" + nID], id);
            iIndex++;
            nID++;
            if (nID > g_nBallCount)
                nID = 1;
        }
        
        g_bMove = true;
    }
}

function SetMethods()
{
    var iIndex:Number;
    var crtBall:MovieClip;
    for (iIndex = 0; iIndex < g_nBallCount; iIndex++)
    {
        crtBall = this["ball"+(iIndex+1)];
        crtBall.nID = iIndex + 1;
        crtBall.onRollOver = function()
        {
            this.reverser_mc.gotoAndStop(1);
            this.play(1);
        }
        crtBall.onRollOut = function()
        {
            this.reverser_mc.gotoAndPlay(2);
        }
        
        crtBall.onPress = function()
        {
            this.gotoAndStop(15);
        }
        crtBall.onRelease = function()
        {
            this.gotoAndStop(1);
            SetBallIntervals(this.nID);
        }
    }
}

// initialisations
for (iIndex = 0; iIndex < g_nBallCount; iIndex++)
{
    startX[iIndex] = this["ball"+(iIndex + 1)]._x;
    startY[iIndex] = this["ball"+(iIndex + 1)]._y;
}
SetMethods();
stop();
  1. // variable declaration
  2. var startX:Array = new Array();
  3. var startY:Array = new Array();
  4. var endX:Array = new Array(75, 150);
  5. var endY:Array = new Array(200, 250, 300, 350, 400);
  6. var arrIntervals:Array = new Array();
  7. var g_nBallCount:Number = 5;
  8. var iIndex:Number;
  9. var speed:Number = 10;
  10. var g_bMove = false;
  11. var g_nIntervalIndex:Number = 0;
  12. // functions
  13. function moveMe(targ, id)
  14. {
  15.     var nX:Number = 0;
  16.     var nTolerance = 0.5;
  17.     if (targ.nID == id)
  18.         nX = endX[1];
  19.     else
  20.         nX = endX[0];
  21.         
  22.     nY = endY[targ.nID - 1];
  23.     
  24.     targ._x+=(nX-targ._x)/_root.speed;
  25.     targ._y+=(nY-targ._y)/_root.speed;
  26.     
  27.     if (targ._y - nTolerance <= nY && targ._y + nTolerance >= nY)
  28.         targ._y = nY;
  29.     if (targ._x - nTolerance <= nX && targ._x + nTolerance >= nX)
  30.         targ._x = nX;
  31.         
  32.     if (targ._y == nY && targ._x == nX)
  33.     {
  34.         clearInterval(arrIntervals[targ.nID - 1]);
  35.         g_nIntervalIndex++;
  36.         if (g_nIntervalIndex == g_nBallCount)
  37.         {
  38.             g_bMove = false;
  39.             g_nIntervalIndex = 0;
  40.         }
  41.     }
  42. }
  43. function SetBallIntervals(id)
  44. {
  45.     if (!g_bMove)
  46.     {
  47.         var nID:Number = id;
  48.         var iIndex:Number = 0;
  49.         while (iIndex < g_nBallCount)
  50.         {                
  51.             arrIntervals[nID - 1] = setInterval(moveMe,30,this["ball" + nID], id);
  52.             iIndex++;
  53.             nID++;
  54.             if (nID > g_nBallCount)
  55.                 nID = 1;
  56.         }
  57.         
  58.         g_bMove = true;
  59.     }
  60. }
  61. function SetMethods()
  62. {
  63.     var iIndex:Number;
  64.     var crtBall:MovieClip;
  65.     for (iIndex = 0; iIndex < g_nBallCount; iIndex++)
  66.     {
  67.         crtBall = this["ball"+(iIndex+1)];
  68.         crtBall.nID = iIndex + 1;
  69.         crtBall.onRollOver = function()
  70.         {
  71.             this.reverser_mc.gotoAndStop(1);
  72.             this.play(1);
  73.         }
  74.         crtBall.onRollOut = function()
  75.         {
  76.             this.reverser_mc.gotoAndPlay(2);
  77.         }
  78.         
  79.         crtBall.onPress = function()
  80.         {
  81.             this.gotoAndStop(15);
  82.         }
  83.         crtBall.onRelease = function()
  84.         {
  85.             this.gotoAndStop(1);
  86.             SetBallIntervals(this.nID);
  87.         }
  88.     }
  89. }
  90. // initialisations
  91. for (iIndex = 0; iIndex < g_nBallCount; iIndex++)
  92. {
  93.     startX[iIndex] = this["ball"+(iIndex + 1)]._x;
  94.     startY[iIndex] = this["ball"+(iIndex + 1)]._y;
  95. }
  96. SetMethods();
  97. stop();
  • dlacloche
  • Born
  • Born
  • dlacloche
  • Posts: 2
  • Loc: Madison, WI

Post 3+ Months Ago

Wow.

I knew my code was repetative and not so good, but as a newbie, I surely couldn't put it together the way that you have. Thanks.

How long have you been doing this? How did you learn your skills? I'm trying to learn the ActionScript language using The Flash 8 ActionScript Bible [and trial and error].

What ingredients in my code make the movieClips jump all around like spasms? I even added a button symbol not related to the other movieClip buttons, and when I rolled over that it made the balls jump and spasm halfway across the stage for no reason.

I'm going to re-read your code a few times and give it a try.

Thanks again.

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 12 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.