Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
kittichai

TransformMatrixPlugin - Matrix is null

Recommended Posts

My program cause error in TransformMatrixPlugin at the code here:

 


	override public function onInitTween(target:Object, value:*, tween:TweenLite):Boolean {
		_transform = target.transform as Transform;
		_matrix = _transform.matrix;
		var matrix:Matrix = _matrix.clone();

It cause TypeError: Error #1009: Cannot access a property or method of a null object reference.

at com.greensock.plugins::TransformMatrixPlugin/onInitTween()[D]

because, somehow, the target's matrix is null.

 

I have created short actionscript class to test my understanding on TransformMatrixPlugin, and it works just fine.

 

I try to solve this problem by assign new Matrix to its matrix before creating Tween, like this:

 

target.transform.matrix = new Matrix();

 

Which I have debug and see that it's definitely not null. The error persist.

 

So, I put the following code into TransformMatrixPlugin.as

 

	override public function onInitTween(target:Object, value:*, tween:TweenLite):Boolean {
		_transform = target.transform as Transform;
		_matrix = _transform.matrix;
		if (_matrix == null) {                             // New Code
			_matrix = new Matrix();                  // New Code
		}                                                            // New Code
		var matrix:Matrix = _matrix.clone();

 

And the error disappear. Program works smoothly.

 

Will this be added to official greensock library? I don't know why my displayObject's matrix became null, and it's not greensock's error. But, this 3 lines of code solve the problem and doesn't seem to affect anything else.

 

If you can add this into official library, I will be glad that I don't have to keep changing this code everytime I update the library

Thanks.

Link to comment
Share on other sites

It sounds like you must be tweening some 3D property or applying a 3D property at some point to your DisplayObject. This causes the matrix3D to be populated and the matrix to be set to null (by Flash, not TweenLite/Max). You shouldn't use transformMatrix anyway if you've got 3D properties applied to your DisplayObject because it wouldn't make sense - transformMatrix is only for 2D operations which cannot be mixed with 3D ones.

 

I also wouldn't want to add the snippet you suggested to the plugin because setting the matrix to a new Matrix() will completely erase all transform properties like x/y/scaleX/scaleY/rotation and return them to normal (x:0, y:0, scaleX:1, scaleY:1, rotation:0). See the problem?

 

If you're still having issues, please post a sample FLA with the simplest code possible to reproduce the issue so that we can just publish and see it immediately.

Link to comment
Share on other sites

I did put some rotation in my code and it cause that error. If I change rotationX, Y, or Z it will cause error, even though rotationZ is not quite 3D effect.

I understand your point about creating new Matrix() will cause all previous rotation to be overwritten, so my modification won't work.

 

However, there's variety of animation that 3D transform can be useful, will you make TransformMatrix3D anytime soon?

Link to comment
Share on other sites

Help me understand what benefit you see in a transformMatrix3D plugin. Why wouldn't you just do regular tweens of the standard properties like rotationX, rotationY, rotationZ, z, etc.?

Link to comment
Share on other sites

There's lot of benefit if I can have TransformMatrix3DAroundCenter.

Of course, I can use scale and rotation to manipulate shape of object, but Actionscript base rotation point around 0,0,0, which limit animation effect and hard to calculate the spot to move object to make effect looks more like rotation around center. (May be not hard for you, but for me who have very limited knowledge in Trigonometry)

Right now, I can't use your TransformAroundCenter if I have applied any rotation (either X,Y or Z will cause this error).

Link to comment
Share on other sites

Oh, now I see the confusion - your post's title has "TransformMatrixPlugin" but you were actually talking about the TransformAroundCenterPlugin/TransformAroundPointPlugin. Totally different beasts. You can actually use the TweenProxy3D class I built if you want to define a custom registration point in 3D space. It sounds like that's what you're after anyway. There's an interactive demo included in the recent downloads for Club GreenSock members.

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