PDA

View Full Version : importing Tweener problems ( Error:1180 )


Slowburn
06-18-2007, 07:01 PM
Hi All, I'm trying to add Tweener ( AS3 ) to my application.

I'm able to get it to work on a simple Flash Movie, however, porting it over to my app is becoming frustrating.

My main movie has a document-class "App.as" this attaches a Sprite from the library called "View".

View imports the Tweener Class. I then try to add a tween, and I get....

"1180: Call to a possibly undefined method addTween." ?? what?
I have other singleton classes and they work fine. I also have used a classPath to the Tweener AS code in my main movie.

could anyone help me out? I can't seem to figure this out.

panel
06-18-2007, 10:11 PM
Technicly it should work.

Can you prepare example for review ?

Slowburn
06-18-2007, 10:19 PM
Any example that I've created ( from scratch ) has worked. just not in my code. lol.


I thought that it might be because Tweener wasn't public, but, alas...it is...so that's not it.

plutocrat
06-18-2007, 10:50 PM
Hmm.

The reason that addTween() is undefined is because it does not exist. I have never scripted tweens before in AS3, and your question made me decide to learn. I was pleasantly surprised; the implementation is simple yet incredibly powerful.

Here is a class I made as an example:

package com.tweenExample {

import fl.transitions.Tween
import fl.transitions.easing.Elastic;

import flash.display.MovieClip;
import flash.display.Sprite;

public class TweenExampleApp extends Sprite {

private var image:MovieClip;
private var imageTween:Tween;

public function TweenExampleApp():void {

//Create Image to be Tweened
image = new MovieClip()
image.x = image.y = 100
with (image.graphics) {
beginFill(1)
drawCircle(0,0,10)
endFill()
}
image.cacheAsBitmap = true;
addChild(image)

//Create Tween
imageTween = new Tween(image, "x", Elastic.easeInOut, 100, 200, 3, true)

}
}
}

Does this help?

plutocrat
06-18-2007, 11:07 PM
Or, for the far more unnerving version (try to run away from it with the mouse):

package com.tweenExample {

import fl.transitions.Tween
import fl.transitions.easing.Bounce

import flash.display.MovieClip;
import flash.display.Sprite;
import flash.utils.Timer;
import flash.events.TimerEvent;

public class TweenExampleApp extends Sprite {

private var image:MovieClip;
private var imageTweenX:Tween;
private var imageTweenY:Tween;
private var uT:Timer;

public function TweenExampleApp():void {

//Create Image to be Tweened
image = new MovieClip()
image.x = image.y = 100
with (image.graphics) {
beginFill(1)
drawCircle(0,0,10)
endFill()
}
image.cacheAsBitmap = true;
addChild(image)

//Create Tween
imageTweenX = new Tween(image, "x", Bounce.easeOut, mouseX, mouseX, 100, true)
imageTweenY = new Tween(image, "y", Bounce.easeOut, mouseY, mouseY, 100, true)
imageTweenX.looping = imageTweenY.looping = true;

//Create Timer
uT = new Timer(1)
uT.addEventListener(TimerEvent.TIMER, update, false, 0, true)
uT.start()

}
public function update($evt:TimerEvent):void {
imageTweenX.finish = mouseX
imageTweenX.begin = image.x
imageTweenY.finish = mouseY
imageTweenY.begin = image.y
}

}
}

For me at least, that tripped some raw primitive instinct that tells me that something is really not right. Perhaps it is due to the knowledge that in 100 seconds, however fast I run, it WILL reach me. How odd...

Slowburn
06-18-2007, 11:44 PM
I'm using the AS3 version of Tweener (http://code.google.com/p/tweener/) not the native Tween from fl.transitions. Although, I've also had problems using the native Flash Tween aswell (post here (http://www.actionscript.org/forums/showthread.php3?t=139413))

sasxa
06-18-2007, 11:46 PM
I have never scripted tweens before in AS3, and your question made me decide to learn. I was pleasantly surprised; the implementation is simple yet incredibly powerful.


I also decided earlier today to see what's there. one great thing I've noticed is that in Tween class definition 2nd argument is String with "" value as default. What this means is that you can use Tween for all sorts of things. Example:

var twAnimation:Tween = new Tween(object, "", Bounce.easeIn, 0, 1, 1, true);
twAnimation.addEventListener(TweenEvent.MOTION_CHA NGE, doSmtng);

function doSmtng(e:TweenEvent):void {
var value = e.currentTarget.position; //this holds value that's changing...
var object = e.currentTarget.obj;
object.x = value * 100; // move left 100px
object.y = value * -50; // move up 50px
object.alpha = value;
// I made some more complex effects, like
object.transform.colorTransform.redOffset = value * 0xFF;
// etc...
}

really cool class :)

plutocrat
06-19-2007, 05:27 PM
@SlowBurn: Sorry! I had not realised that Tweener was an external library. I take back my subtle insinuation that you were slightly simple and place the dunce's cap firmly on my own head.

That said, I had a look a Tweener and it seems like a bit of a dumbed-down clown suit for the fl.transitions package. Certainly it would be useful for simple applications of the package, but more complex ones would start be become very tiring.

I hope that my example shed at least some light on the issue you had in the other thread. I don't really understand what you meant about 'finishing early'; try fiddling with the tween function (e.g. Regular.easeOut --> Bounce.easeOut, etc.).

@sacxa: Clever, clever, clever. It seems annoying for such applications of the Tween class that you need an MC at all.

Nevertheless, it is an intriguing notion: you could tween Strings and all sorts of interesting things. Thanks for the lateral thinking. :)