dasneko Posted March 18, 2015 Share Posted March 18, 2015 The problem that I am dealing with is passing Pipets into the 2nd onComplete. It returns an undefined even though I try to declare it a global variable. In most case, only the last value of the array get pass in instead of 1-9. I am terrible at javascript and pixijs so please point it out since I've spent so many hours trying to figure this out.for (var i = 0; i < 9; i++) { if (i !== 7) { Pipets = []; Pipets[i] = new Pipette(); Pipets[i].x = 273 + 80 * i; Pipets[i].y = -320; TweenMax.to(Pipets[i], 1.5, { y: 145, ease: Sine.easeInOut, onComplete: function (index) { var tube = tubeArray[index]; TweenMax.to(tube.broth, 1, { y: tube.broth.y - 30, ease: Sine.easeInOut, onComplete: function () { TweenMax.to(Pipets[i], 1.5, { y: -350, ease: Sine.easeInOut });} }); }, onCompleteParams: [i] }); stage.addChild(Pipets[i]); }} Quote Link to comment Share on other sites More sharing options...
kyptov Posted March 18, 2015 Share Posted March 18, 2015 this is a closure. It always works that. http://stackoverflow.com/questions/6425062/passing-functions-to-settimeout-in-a-loop-always-the-last-value Quote Link to comment Share on other sites More sharing options...
dasneko Posted March 18, 2015 Author Share Posted March 18, 2015 I might need more hand holding with this. Quote Link to comment Share on other sites More sharing options...
dasneko Posted March 18, 2015 Author Share Posted March 18, 2015 Found the issue. Pipets = []; was being declare again every time in the loop so only the last thing was actually in there. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.