Jump to content
Search Community

transformaroundcenter not working on bitmap [SOLVED]

Guest drpelz
Moderator Tag

Recommended Posts

Guest drpelz

hi, I get a strange error when I try to use the transformaroundcenter-plugin on a bitmap:

 

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

at com.greensock.plugins::TransformAroundPointPlugin/onInitTween()

at com.greensock.plugins::TransformAroundCenterPlugin/onInitTween()

at com.greensock::TweenLite/init()

at com.greensock::TweenLite/renderTime()

at com.greensock.core::SimpleTimeline/renderTime()

at com.greensock::TweenLite$/updateAll()

 

Does anyone have an idea where the problem might be? I really appreciate every hint to solve this problem. Thank you very much in advance.:)

 

Currently my code is (not complete):

import com.greensock.*;
import com.greensock.TweenLite;
import com.greensock.plugins.TweenPlugin;
import com.greensock.plugins.TransformAroundCenterPlugin;

TweenPlugin.activate([TransformAroundCenterPlugin]);

TweenLite.to(tempScore.bitmap, 2, {transformAroundCenter: {scale:2}});

package com.cosmicward.src.classes 
{
import flash.display.*;
import flash.text.*;
import flash.geom.*;

import com.framework_mod.src.BlitArrayAsset;


public class ScoreManager 
{
	public var scoreBitmapData:BitmapData;
	public var scoreBitmap:Bitmap;

	public var scoreAnimationFrames:Array = [];

	public var scores:Array;
	public var tempScore:Score;		
	private var textfield:TextField = new TextField();
	private var textFormat:TextFormat = new TextFormat();
	private var $textWidth:int;
	private var $textHeight:int;


	private var rec:Rectangle;

	public var scoreCount:int;
	public var scoreCountTwo:int;
	public var scoreCountThree:int;

	private var drawingCanvas:Shape = new Shape();	

	private var point0:Point = new Point(0, 0);


	public function ScoreManager() 
	{

	}


	public function createScoreLook(textWidth:int, textHeight:int, text:String, textFormat:TextFormat):void {


		var tempBlitArrayAsset:BlitArrayAsset = new BlitArrayAsset();


		scoreBitmapData = new BitmapData(textWidth, textHeight, true, 0x00000000);

		var font:ArialBold = new ArialBold();
		textFormat.font = "ArialBold";
		textFormat.font = font.fontName;
		Font.registerFont(ArialBold);

		textfield.embedFonts = true;
		textfield.blendMode = BlendMode.LAYER;
		//textfield.autoSize = TextFieldAutoSize.LEFT;
		textfield.defaultTextFormat = textFormat;
		textfield.setTextFormat(textFormat);
		textfield.selectable = false;
		textfield.text = text;


		trace("drawingCanvas.height =" + drawingCanvas.height);
		trace("drawingCanvas.width =" + drawingCanvas.width);

		scoreBitmapData.draw(textfield);/



		$textWidth = textWidth;
		$textHeight = textHeight;

		//*** end look

	}



	public function createScores(xPos:Number, yPos:Number, stopAnimation:int = 5,
								 scoreDelay:int = 10, scoreLife:int = 40):void {

			var tempScore:Score = new Score(5, 1315, 5, 995);

			tempScore.bitmapData = scoreBitmapData;

			scoreBitmap = new Bitmap(tempScore.bitmapData);

			tempScore.bitmap = scoreBitmap;


			tempScore.x = xPos;
			tempScore.y = yPos;

			tempScore.life = scoreLife;
			tempScore.lifeCount = 0;

			tempScore.widthObject = $textWidth;
			tempScore.heightObject = $textHeight;

			tempScore._delay = scoreDelay;
			tempScore.delayCount = 0;

			tempScore.nextX = tempScore.x;
			tempScore.nextY = tempScore.y;

			scores.push(tempScore);
			}
	}
}

Link to comment
Share on other sites

In cases like this, it is likely that TweenLite isn't doing what you expect because you are asking it to tween something that doesn't exist, not that it can't tween a bitmap.

 

right above your TweenLite tween add:

 

trace("tempScore.bitmap = " + tempScore.bitmap);

 

if you get null or undefined than you have to find out why.

 

-------

 

after looking through your code, inside a function you have:

 

var tempScore:Score = new Score(5, 1315, 5, 995);

 

by putting var in there that means that the variable is only accessible in the scope of that function.

 

try

 

tempScore = new Score(5, 1315, 5, 995);

Link to comment
Share on other sites

Guest drpelz

Ok. I tried that and when I trace the tempScore.bitmap I get:

tempScore.bitmap [object Bitmap]

 

So the object exists. Also I made the variable tempScore public and removed var but I still get the same errors.:(

 

That didn't work because tempScore will be thrown into an array therefore removing var doesn't change anything.

 

What I can tell you is that tempScore inherits properties from an object called BasicBlitArrayObject. On the other hand this BasicBlitArrayObject extends EventDispatcher (I hope that info helps a little bit).

Link to comment
Share on other sites

Guest drpelz

Sorry for my late reply. It's the current version I'm using (2.1).

 

When using a getBounds-Method I get this:

 

tempScore.bitmap.getBounds(this)(x=2.35, y=-0.45, w=25, h=18)

 

There's still this strange error message:

 

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.greensock.plugins::TransformAroundPointPlugin/onInitTween()
at com.greensock.plugins::TransformAroundCenterPlugin/onInitTween()
at com.greensock::TweenLite/init()
at com.greensock::TweenLite/renderTime()
at com.greensock.core::SimpleTimeline/renderTime()
at com.greensock::TweenLite$/updateAll()

 

My imported and activated libraries look like this:

import com.greensock.*;
import com.greensock.TweenLite;
import com.greensock.plugins.TweenPlugin;
import com.greensock.plugins.TransformAroundCenterPlugin;
import com.greensock.plugins.TransformAroundPointPlugin;
import com.greensock.easing.*;
import com.greensock.plugins.AutoAlphaPlugin;
import com.greensock.plugins.ColorTransformPlugin;
import com.greensock.plugins.ColorMatrixFilterPlugin;

TweenPlugin.activate([TransformAroundCenterPlugin, TransformAroundPointPlugin, ColorTransformPlugin,
					  ColorMatrixFilterPlugin]);

 

This is the part where I try to use TweenLite on my tempScore:

 

var scoreTextLength:int = scoreManager.scores.length - 1;
		for (var counter:int = scoreTextLength; counter >= 0; counter--)
		{

				tempScore = scoreManager.scores[counter];
				tempScore.startDelay = true;

				TweenLite.to(tempScore.bitmap, 2, {transformAroundCenter: {scale:2}});
				trace("tempScore.bitmap.getBounds(this)" + tempScore.bitmap.getBounds(this));

				if (tempScore.update())
				{

					disposeScore(counter);

				}
		}

 

 

So far as I can see the getBounds-values are ok. My game is based on a gameframework. There's a renderer inside of it.

Call me an idiot if I'm wrong but is it possible that the renderer of the framework and tweenlite are getting

in each other's way??

 

TweenLite has problems with other similar objects like tempAsteroid. A lot of objects are drawn onto

a canvas with copyPixels.

 

Here is some code of the BasicBlitArrayObject (tempScore rests upon that):

 

package com.framework_mod.src
{
import flash.display.BitmapData;
import flash.geom.Point;
import flash.events.EventDispatcher;
import flash.geom.Rectangle;
import flash.display.Bitmap;

	public class BasicBlitArrayObject extends EventDispatcher{

	public var x:Number = 0;
	public var y:Number = 0;
	public var nextX:Number = 0;
	public var nextY:Number = 0;
	public var dx:Number = 0; 
	public var dy:Number = 0;
	public var frame:int = 0;
	public var bitmapData:BitmapData;
	public var bitmap:Bitmap;
	public var animationList:Array = [];
	public var testList:Array = [];

	public var point:Point = new Point(0, 0);
	public var speed:Number = 0;

	public var xMax:int = 0;
	public var yMax:int = 0;
	public var xMin:int = 0;
	public var yMin:int = 0;

	public var aniType:int = 1;

	public var health:int = 0;
	public var _size:int = 0;
	public var score:int = 0;
	public var _damage:int = 0;
	public var count:int = 0;
	public var bitmapSize:int = 0;
	public var life:int = 0;
	public var lifeCount:int = 0;
	public var startCount:Boolean;
	public var _delay:int = 0;
	public var delayCount:int = 0;
	public var startDelay:Boolean;
	public var _stop:int;
	public var stopAni:Boolean;
	public var stopAniCount:int = 0;
	public var _type:int = 0;
	public var shield:int = 0;
	public var healthPoints:int = 0;
	public var widthObject:int;
	public var heightObject:int;
	public var boost:Number;
	public var boostLfe:int;
	public var weaponLfe:int;
	public var _projXAdjust:Number;
	public var _projYAdjust:Number;
	public var number:int;
	public var _offset:int;
	public var marked:Boolean;
	public var objMove:Boolean;

	public var removeObj:Boolean;
	public var finished:Boolean;



	public function BasicBlitArrayObject(xMin:int, xMax:int, yMin:int, yMax:int) 
	{
		this.xMin = xMin;
		this.xMax = xMax;
		this.yMin = yMin;
		this.yMax = yMax;
		//trace("basicblittarrayobject");
	}



	public function updateFrame(inc:int, aniType:int = 1):void
	{
		frame += inc;
		switch (aniType) {
		case 1:	
				if (frame > animationList.length - 1){
					frame = 0;
				}
				bitmapData = animationList[frame];					
				break;


		case 2:	
				if (frame > animationList.length - 1){
					frame = 0;
				}
				bitmapData = animationList[1][frame];


				break;
		}


	}	



	public function render(canvasBitmapData:BitmapData):void {
		x = nextX;
		y = nextY;
		point.x = x;
		point.y = y;			

		canvasBitmapData.copyPixels(bitmapData, bitmapData.rect, point);
	}


	public function dispose():void {
		bitmapData.dispose();
		bitmapData = null;
		bitmap = null;
		animationList = null;
		point = null;
	}

}

}

Link to comment
Share on other sites

Are you sure that your bitmap is a regular Bitmap object? Remember, TransformAroundCenterPlugin and TransformAroundPointPlugin only work with DisplayObjects. Is your target a DisplayObject? It must be able to accurately report not only getBounds() but also globalToLocal() and localToGlobal(). Have you verified that it has those methods?

Link to comment
Share on other sites

Guest drpelz

Basically my object is an EventDispatcher (not a Display Object I think (tell me if I'm wrong)). Is it possible to use TweenLite with blitted non-display objects like EventDispatchers? Any help appreciated.

 

I just ask because at this thread ( viewtopic.php?f=1&t=5634 ) blitted non-display Objects seem to work too.

 

Some other guy at another forum said that it's probably not working because my objects are blitted to a canvas. So there are no display-objects to tween.

 

I testet the globalToLocal and localToGlobal of my bitmap and got this:

 

var point:Point = new Point(100, 100);

trace("tempScore.bitmap.globalToLocal(point)" + tempScore.bitmap.globalToLocal(point));

Result1:
tempScore.bitmap.globalToLocal(point)(x=100, y=100)

--

trace("tempScore.bitmap.localToGlobal(point)" + tempScore.bitmap.localToGlobal(point));

Result2:
tempScore.bitmap.localToGlobal(point)(x=100, y=100)

 

Please - any help?

Link to comment
Share on other sites

Yep, that's the problem - your object isn't a DisplayObject. TweenLite can definitely tween non-DisplayObjects. It'll tween ANY numeric property of ANY object. However, TransformAroundCenterPlugin and TransformAroundPointPlugin are just for DisplayObjects because there's some complicated stuff they doe with the target's parent, globalToLocal(), localToGlobal(), and getBounds(). If your object implements all those methods/properties accurately, you could conceivably edit the plugins to rip out any DisplayObject casting that they do, but it's not something that's officially supported.

Link to comment
Share on other sites

Guest drpelz

I tried other PlugIns like the colormatrixfilterplugin which does not require a display object. But it still doesn't work. It doesn't show any errors any more when I use this kind of filter - but that's all. No tweens, nothing.

 

MY game rests upon this one: http://www.8bitrocket.com/book/ch11_blastermines.zip. Try to use TweenLite (any function, e.g. transformplugin, colormatrix, whatever) with a blitted object (object is called tempMine inside of the game class called BlasterMines). I'm pretty sure it won't work.

 

Ok, the bitmapData of my object is copied to the canvas by the renderer via the copyPixels-method. To be honest I have absolutely no clue how to change the plugins if I want to use them on my objects successfully. Any hints?

Link to comment
Share on other sites

This sounds like an issue with the game/framework you're using. Unfortunately I don't have the time to devote to analyzing the inner workings of that framework and tracking down the issue there, but if you want to post a very simple FLA that clearly demonstrates the problem I'd be happy to take a peek. Again, the simpler the better - please provide the FLA that I can publish to immediately see the issue. Or you could ask the author of that framework to identify the issue.

Link to comment
Share on other sites

Guest drpelz

Currently I am not able to make such a small fla-file because the game is too closely interlocked with the framework I use. I will write an email to the makers of the framework and hope they can help me out with this extremely nasty problem. Personally I think it's a bug of the framework - but I'm not sure about that part...I will try it again at the next weekend!

Link to comment
Share on other sites

  • 4 weeks later...
Guest drpelz

Hi Greensock,

 

I just made a really really really small version of the problem. The zip is attached to this post and it contains 4 small AS-files + one fla. I think this is the smallest version I can make.

 

Let me explain it: The Asteroid-class is the object that is blitted to the canvas via copyPixels-method. tempAsteroid is an Asteroid-object. The goal is to make TweenLite work with tempAsteroid (currently nothing works). The AsteroidManager-class contains some properties of the Asteroid-object, e.g. the position, direction, the look of the asteroid, etc. The Asteroid-class inherits properties from the BasicBlitArrayObject. 'Main' should be self-explanatory.

 

The Asteroid gets rendered via the render-function inside of 'Main'. There I tried to use TweenLite with tempAsteroid (which is an Asteroid-object) but nothing works. Absolutely nothing.

 

I didn't include Tweenlite so you'll have to put the com.greensock-folder into the same path where the fla is placed. You will see what I mean. I hope you can help me. Sorry for my late reply but I was in hospital and had to do some other things. Keep up the great work.

Link to comment
Share on other sites

Guest drpelz

But didn't you mention that some plugins actually don't require a display object? E.g. if I want to use the colorMatrixFilter I don't need the display object, right? What I want is to change the color and alpha of the object (tempAsteroid). I don't need the scale-function of the transformAroundCenter-plugin anymore. Tell me if I'm wrong but I'm sure you can tween non-display objects (like tempAsteroid) with the appropriate plugin (like colorMatrixFilter which doesn't need display objects).

Link to comment
Share on other sites

Guest drpelz

I sit possible to make a solution similar to this thread: viewtopic.php?f=1&t=5634 ? I ask because in this thread the plugins had to be modified to work correctly (e.g. if I want to change the alpha of my object what do I have to change inside of the appropriate plugin?)

Link to comment
Share on other sites

I sit possible to make a solution similar to this thread: viewtopic.php?f=1&t=5634 ? I ask because in this thread the plugins had to be modified to work correctly (e.g. if I want to change the alpha of my object what do I have to change inside of the appropriate plugin?)

I don't see how this could possibly be useful - are you saying that you want to transformAroundCenter an object that's not in the display list (so you'd never see it)? Why not just addChild() it to a Sprite or something?

Link to comment
Share on other sites

Guest drpelz

Well, in a previous post of this thread you said this:

 

Yep, that's the problem - your object isn't a DisplayObject. TweenLite can definitely tween non-DisplayObjects. It'll tween ANY numeric property of ANY object. However, TransformAroundCenterPlugin and TransformAroundPointPlugin are just for DisplayObjects because there's some complicated stuff they doe with the target's parent, globalToLocal(), localToGlobal(), and getBounds(). If your object implements all those methods/properties accurately, you could conceivably edit the plugins to rip out any DisplayObject casting that they do, but it's not something that's officially supported.

 

That's the reason I ask for this. My object is tempAsteroid.bitmap. There's globalToLocal, localToGlobal and getBounds. Any chance for modifiying the plugin so it would work?

 

The problem is the following: my objects (e.g. asteroids) are drawn onto a much larger canvas than the one shown in the example. There is a scrollrect so you just see a portion of it (scolling). Now if I add sprites to the display list which contain data of tempAsteroid then I think it won't work because in my case everything is drawn onto the canvas and disappears when it reaches the border of the scrollrect (I hope you know what I mean). Therefore adding stuff to the display list would cause the objects not to disappear because in this case they are just placed onto the stage, right?

 

Other approach: If I want to tween the alpha or color of my tempAsteroid then you don't need display objects, right? Is there any chance to modify the plugins so it would work with my objects?

Link to comment
Share on other sites

Nope, transformAroundCenter and transformAroundPoint REQUIRE that the object not only implement globalToLocal(), localToGlobal(), and getBounds() but also have a "parent" that implements the same methods. If it doesn't have a parent, it won't work. You could put them into a Sprite that has its visible property set to false if you want (so that it doesn't get blitted into your other stuff).

Link to comment
Share on other sites

  • 2 weeks later...
Guest drpelz

Believe it or not but I got the problem solved and TweenLite works like a charm now. This is the solution: I created a backgroundSprite and put my canvasBitmap (that thing is used to blit all stuff on it except the score and some other stuff) inside of it via addChild. After that I added my tempScore via addChild to my backgroundSprite. I had to make some changes to my tempScore-object, i.e. it's not a BasicBlitArrayObject anymore. Now it's a sprite. And it's a DisplayObject added to my background via addChild. Now everything runs perfectly.

 

Basically this is the code. A guy at another forum helped me out with the problem and this is the solution (beware: just an excerpt; no real code):

 

function updateContentRect():void 
{ 
   contentRect.x = Math.max(0, Math.min(659, player.x-330)); 
   contentRect.y = Math.max(0, Math.min(499, player.y-250)); 
   world.scrollRect = contentRect; 
} 

var contentRect:Rectangle = new Rectangle(0,0,660, 500); 
var world:Sprite = new Sprite(); 
world.addChild(background); 

var unitsContainer:Sprite = new Sprite(); 
world.addChild(unitsContainer); 

var birdsContainer:Sprite = new Sprite(); 
world.addChild(birdsContainer); 

unitsContainer.addChild(player); 
updateContentRect(); 

unitsContainer.addChild(enemy); 
birdsContainer.addChild(score); 

player.x += //... 
player.x += //... 
updateContentRect(); 

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