Jump to content
Search Community

weird behavior

joselalupa test
Moderator Tag

Recommended Posts

i have this code wich tween rotation of a mc.

import com.greensock.*

var myMC:MovieClip = new MovieClip();
myMC.graphics.beginFill(0x00ff00);
myMC.graphics.drawRect(0, 0, 400, 300);
myMC.graphics.endFill();
myMC.x = myMC.y = 00;
addChild(myMC);

var Flecha:flecha = new flecha;
addChild(Flecha);
Flecha.x = Flecha.y = 200;

var rotacion:int = 0;

myMC.addEventListener(MouseEvent.MOUSE_DOWN, drag);
function drag(e:MouseEvent){
myMC.startDrag();
}

myMC.addEventListener(MouseEvent.MOUSE_UP, drop);
function drop(e:MouseEvent){
myMC.stopDrag();
myMC.x = myMC.y = 00;
}

this.addEventListener(Event.ENTER_FRAME,myFunction);
function myFunction(event:Event) {

rotacion += myMC.x /60;
TweenMax.to(Flecha,5, {rotation:rotacion});
//Flecha.rotation += myMC.x/20;
trace(rotacion);
trace(rotacion + "cono")
}

 

when i don't use the tween it rotate fine but when using tween and pressing the mouse for a couple of seconds or doing a big rotation the tween enters in a loop.

any idea about this?

Link to comment
Share on other sites

In Flash, rotation is ALWAYS reported as being between -180 and 180. You can set the value to anything, but when you read it back, it will fall within that range. For example:

 

mc.rotation = 710;
trace(mc.rotation); //reports -10

 

So your code uses a variable that keeps getting bigger and bigger, well beyond 180. When the tween begins, it captures the starting value and ending value and...tweens between them. In your case, imagine what happens when the rotacion variable gets bigger, like 710. The tween will indeed honor your request to go to that large value, but then when the next tween begins, its starting value which gets reported by Flash will be much lower, between -180 and 180. There's your problem.

 

If it were me, I'd probably just track the target and current rotation values in variables and tween the current rotation and use an onUpdate to apply the variable to the myMC.rotation like this:

 

var targetRotation:int = 0;
var currentRotation:Number = myMC.rotation;

myMC.addEventListener(MouseEvent.MOUSE_DOWN, drag);
function drag(e:MouseEvent) {
myMC.startDrag();
this.stage.addEventListener(MouseEvent.MOUSE_UP, drop);
}

function drop(e:MouseEvent) {
this.stage.removeEventListener(MouseEvent.MOUSE_UP, drop);
myMC.stopDrag();
myMC.x = myMC.y = 00;
}

this.addEventListener(Event.ENTER_FRAME,myFunction);
function myFunction(event:Event) {
if (myMC.x != 0) {
	targetRotation += myMC.x / 60;
	TweenMax.to(this, 5, {currentRotation:targetRotation, onUpdate:applyRotation});
}
}
function applyRotation():void {
myMC.rotation = currentRotation;
}

 

Also, just for the record, if you want to use TweenMax's ability to figure out the shortest distance to a particular rotation value, you can use the ShortRotationPlugin. TweenMax.to(myMC,5, {shortRotation:{rotation:rotacion}}); but that's not a perfect solution here because you're not always wanting to go the shortest route.

Link to comment
Share on other sites

sorry for hammering on this post...i check the solution and it worked but not in the project i am working on.

using "this" in the tween does not work.

a) is there any way i could substitute "this" for any other object?

B) what is referencing "this" ?

Link to comment
Share on other sites

it is important to note that in GreenSock's solution he is not directly tweening the rotation of myMC.

 

he is tweening the currentRotation property which lives within the scope of the main timeline, in this case "this".

 

the main timeline has a var/property called currentRotation.

 

when currentRotation gets tweened, the the onUpdate function updates the rotation of myMC.

 

his code was written for a very exact solution to the code you specified.

If you want to implement his suggestion in another project, feel free to modify it to suit your needs.

 

In general, yes, you can tween any property of any object, you are not forced to use "this". you simply reference the object who's properties you want to tween.

Link to comment
Share on other sites

maybe i didn't make my self clear...in this line can i substitute "this" for other object?

 TweenMax.to(this, 5, {referRotation:targetRotation, onUpdate:applyRotation});

thanks and sorry for my ignorance.

 

now i noticed the code i have just works directly on the fla, if i place it in a clase it stop working because of the same...."this"

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...