Jump to content
Search Community

Can't get transformAroundCenter to work properly

kamcknig test
Moderator Tag

Recommended Posts

Hi everyone, I'm trying to scale an item in the y direction, and then scale it in the x direction using the transformAroundCenter plug-in with TweenLite. Here is my code for when an external SWF file has been loaded into my movie.

 

private function onResumeLoaded(e:Event):void
{
e.target.removeEventListener(Event.COMPLETE, onResumeLoaded);
var loader:Loader = e.target.loader as Loader;
loader.scaleX = .01;
loader.scaleY = .01;
loader.x = stage.stageWidth / 2 - loader.width / 2;
loader.y = stage.stageHeight / 2 - loader.height / 2;
addChild(loader);

var yTween:Object = new Object();
yTween.transformAroundCenter = new Object();
yTween.transformAroundCenter.scaleY = 1;
yTween.onCompleteParams = [loader];

yTween.onComplete = function(loader:Loader):void
{
	var xTween:Object = new Object();
	xTween.transformAroundCenter = new Object();
	xTween.transformAroundCenter.scaleX = 1;
	TweenLite.to(loader, .5, xTween);
}

TweenLite.to(loader, .5, yTween);
}

 

But when this executes... the y scale tween works fine and it scales it and keeps it centered on the stage like it should, but when the y tween is complete and the x tween goes, then as it scales, it moves off to the left rather than staying centered! Anyone know why?

 

Thanks!

Kyle

Link to comment
Share on other sites

I would try taking out the nested function which is a bad idea anyway. See if this works for you:

private function onResumeLoaded(e:Event):void
{
  e.target.removeEventListener(Event.COMPLETE, onResumeLoaded);
  var loader:Loader = e.target.loader as Loader;
loader.scaleX = .01;
loader.scaleY = .01;
loader.x = stage.stageWidth / 2 - loader.width / 2;
loader.y = stage.stageHeight / 2 - loader.height / 2;

var yTween:Object = new Object();
yTween.transformAroundCenter = new Object();
yTween.transformAroundCenter.scaleY = 1;
yTween.onComplete = onTweenComplete;
yTween.onCompleteParams = [loader];

TweenLite.to(loader, 0.5, yTween);
}

private function onTweenComplete(loader:Loader):void
{
var xTween:Object = new Object();
xTween.transformAroundCenter = new Object();
xTween.transformAroundCenter.scaleX = 1;
TweenLite.to(loader, 0.5, xTween);
}

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...