Core object does not contain tween [SOLVED]


(meganmorgangames) #1

Probably doing this the hard way to begin with, but it was the only way I could figure out how to keep track of which QuadMotion was finishing its tween. I get the “Core object does not contain tween” error when the first object finishes its tween.

	public function butterflyDone():void {
		var checkNumber:int = 0;
		for each(var t:QuadMotion in _butterflyTween) {
			trace(t.percent);
			if (t.percent >= 1) {
				removeTween(t);
				moveButterfly(checkNumber);
				checkNumber++;
			}
		}
	}
	
	public function moveButterfly(actor:int):void {
		//trace(actor);
		_butterflyTween[actor] = new QuadMotion(butterflyDone);
		var p:Vector.<Number> = new Vector.<Number>();
		for (var loop:int = 0; loop < 6; loop++) {
			p.push((Math.random() * _moveBorder) - _moveOffset);
		}
		_butterflyTween[actor].setMotion(_butterflyStart[actor].x, _butterflyStart[actor].y, p[2], p[3], p[4], p[5], (Math.random() * 2) + 2,Ease.quadInOut);
		_butterflyTween[actor].object = _butterflyImages[actor];
		addTween(_butterflyTween[actor], true);
		_butterflyStart[actor] = new Point(p[4], p[5]);
	}

(Martí Angelats i Ribera) #2

What are you trying to do? Isn’t it better to create a Class for that?


(Jacob Albano) #3

That’s a matter of coding preference. It has nothing to do with the actual problem at hand.


(meganmorgangames) #4

I guess I could, but I was hoping that keeping these images in the same graphiclist would make it run a little faster. Basically, the butterflies will move along a bezier curve to a random point, then pick another random point and move there. I want the to move at different speeds. It’s really just a fluff graphic, with no real mechanics. When they were all set to duration 2, I didn’t get this error. I started getting it when I tried to randomize the duration of the tween.

If it’s not an easy fix, I can create butterfly entities that follow their own individual tweens.


(Jacob Albano) #5

The function you’re setting as a completion callback will remove every single tween you’ve added. If I’m understanding your code correctly, this callback runs every time any of your tweens end, so after the first time it will try to remove tweens that have already been removed.

Try using a closure for this instead:

public function moveButterfly(actor:int):void {
     // declare this inside the other function to capture the value of "actor"
    function butterflyDone() {
        removeTween(_butterflyTween[actor]);
        moveButterfly(actor);
    }

    // do the rest of your tween code
}

(meganmorgangames) #6

Thank you. That worked perfectly. I had never considered nesting the functions. :smile:


(Jacob Albano) #7

Glad I could help! I use closures all the time, and it’s fun to introduce them to people. One thing to be careful of though; inside closures and callbacks, this might not always refer to the object you intend it to. I wrote about that on my blog.