AS3.0 Augmented Reality 1046 Error - actionscript-3

I am having an Error on the loop function can anyone tell me what i am doing wrong?
I think my syntax is good?
Severity and Description Path Resource Location Creation Time Id
1046: Type was not found or was not a compile-time constant: Event. ar/src ar.as line 94 1318225764229 228
package {
import flash.display.Sprite;
import org.papervision3d.objects.primitives.Cube;
[SWF(width="640", height="480", framerate="30", backgroundColor="#ffffff")]
public class ar extends Sprite
{
// Embed the marker.pat file
[Embed(source="marker.pat", mimeType="application/octet-stream")]
private var marker:Class;
// Embed the camera.pat file
[Embed(source="camera_para.dat", mimeType="application/octet-stream")]
private var cam_params:Class;
// createFLAR Vars
private var ar_params:FLARParam;
private var ar_marker:FLARCode;
// createCAM Vars
private var ar_vid:Video;
private var ar_cam:Camera;
// createBMP Vars
private var ar_bmp:BitmapData;
private var ar_raster:FLARRgbRaster_BitmapData;
private var ar_detection:FLARSingleMarkerDetector;
// createPapervision Vars
private var ar_scene:Scene3D;
private var ar_3dcam:FLARCamera3D;
private var ar_basenode:FLARBaseNode;
private var ar_viewport:Viewport3D;
private var ar_renderengine:BasicRenderEngine;
private var ar_transmat:FLARTransMatResult;
private var ar_cube:Cube;
public function ARProj()
{
createFLAR();
createCAM();
createBMP();
createPapervision();
addEventListener(Event.ENTER_FRAME, loop);
}
public function createFLAR()
{
ar_params = new FLARParam();
ar_marker = new FLARCode();
ar_params.loadParam(new cam_params() as ByteArray);
ar_marker.loadARPatt(new marker());
}
public function createCAM()
{
ar_vid = new Video(640, 480);
ar_cam = Camera.getCamera();
ar_cam.setMode(640,480,30);
ar_vid.attachCamera(ar_cam);
addChild(ar_vid);
}
public function createBMP()
{
ar_bmp = new BitmapData(640,480);
ar_bmp.draw(ar_vid);
ar_raster = new FLARRgbRaster_BitmapData(ar_bmp);
ar_raster = new FLARSingleMarkerDetector(ar_params, ar_marker, 80);
}
public function createPapervision()
{
ar_scene = new Scene3D();
ar_3dcam = new FLARCamera3D(ar_params);
ar_basenode = new FLARBaseNode();
ar_renderengine = new BasicRenderEngine();
ar_transmat = new FLARTransMatResult();
ar_viewport = new Viewport3D();
var ar_light:PointLight3D = new PointLight3D();
ar_light.x = 1000;
ar_light.y = 1000;
ar_light.z = -1000;
var ar_bitmap:BitmapMaterial;
ar_bitmap = new BitmapFileMaterial("image.jpeg");
ar_bitmap.doubleSided = true;
ar_cube = new Cube(new MaterialsList({all:ar_bitmap}), 80, 80, 80);
ar_scene.addChild(ar_baseNnode);
ar_basenode.addChild(ar_cube);
addChild(ar_viewport);
}
public function loop(e:Event):void
{
ar_bmp.draw(ar_vid);
ar_cube.rotationX +=4;
ar_cube.rotationY +=6;
try
{
if (ar_detection.detectMarkerLite(ar_raster, 80) && ar_detection.getConfidence() > 0)
{
ar_detection.getTransformMatrix(ar_transmat);
ar_basenode.setTransformMatrix(ar_transmat);
ar_renderengine.renderScene(ar_scene, ar_3dcam, ar_viewport);
}
}
catch(e:Error){
}
}
}
}

import flash.events.Event;
You have not imported Event class. Add this import.

You're missing the import for the event Class (and probably more).

Related

ActionScript 3 Apparently I cannot access movieclip

I've created a zoom function but when I try to scale the bg_image nothing happends. It is like I cannot access it's properties. Does anyone know why? :)
Ty!
Main class
package
{
import flash.display.MovieClip;
import flash.utils.Dictionary;
import flash.events.MouseEvent;
import flash.display.Sprite;
import flash.text.TextField;
import fl.controls.Button;
import fl.controls.List;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.events.Event;
import flash.display.Shape;
import fl.transitions.Fly;
import fl.motion.MatrixTransformer;
import flash.events.KeyboardEvent;
import flash.geom.Matrix;
import flash.geom.Point;
import flash.ui.Mouse;
public class Main extends Sprite
{
// Zoom
public static var scale:Number = 1;
public var spImage:Sprite;
public var mat:Matrix;
public var mcIn:MovieClip;
public var mcOut:MovieClip;
public var boardWidth:int = 980;
public var boardHeight:int = 661;
public var boardMask:Shape;
public var externalCenter:Point;
public var internalCenter:Point;
public const scaleFactor:Number = 0.8;
public var minScale:Number = 0.25;
public var maxScale:Number = 10.0;
// ------------------------
// Grafikk
public var bg_image:Sprite;
//-------------------------------
//-----------------------------------------------
public var routeArray:Array;
public var startList:List = new List();
public var sluttList:List = new List();
public var S_Norway:Dictionary = new Dictionary();
public var S_Australia:Dictionary = new Dictionary();
public var S_China:Dictionary = new Dictionary();
public var S_South_Africa:Dictionary = new Dictionary();
public var S_Brazil:Dictionary = new Dictionary();
public var S_USA:Dictionary = new Dictionary();
public var S_France:Dictionary = new Dictionary();
// ------------------------------------------------------
public static var airportDict:Dictionary = new Dictionary();
public function Main()
{
addEventListener(Event.ADDED_TO_STAGE, init);
// ---------------------------------
}
public function init(e:Event):void
{
bg_image = new Image(0, 0);
this.addChild(bg_image);
bg_image.addEventListener(MouseEvent.CLICK, mouseCoordinates);
removeEventListener(Event.ADDED_TO_STAGE, init);
// Zoom
this.graphics.beginFill(0xB6DCF4);
this.graphics.drawRect(0,0,boardWidth,boardHeight);
this.graphics.endFill();
spImage = new Sprite();
this.addChild(spImage);
boardMask = new Shape();
boardMask.graphics.beginFill(0xDDDDDD);
boardMask.graphics.drawRect(0,0,boardWidth,boardHeight);
boardMask.graphics.endFill();
boardMask.x = 0;
boardMask.y = 0;
this.addChild(boardMask);
spImage.mask = boardMask;
minScale = boardWidth / bg_image.width;
mcIn = new InCursorClip();
mcOut = new OutCursorClip();
bg_image.addChild(mcIn);
bg_image.addChild(mcOut);
bg_image.scaleX = minScale;
bg_image.scaleY = minScale;
spImage.addChild(bg_image);
spImage.addChild(mcIn);
spImage.addChild(mcOut);
spImage.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
stage.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
spImage.addEventListener(MouseEvent.CLICK, zoom);
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyHandler);
stage.addEventListener(KeyboardEvent.KEY_UP, keyHandler);
S_USA["x"] = 180.7;
S_USA["y"] = 149.9;
S_USA["bynavn"] = "New York";
S_Norway["x"] = 423.7;
S_Norway["y"] = 76.4;
S_Norway["bynavn"] = "Oslo";
S_South_Africa["x"] = -26;
S_South_Africa["y"] = 146;
S_South_Africa["bynavn"] = "Cape Town";
S_Brazil["x"] = 226;
S_Brazil["y"] = 431.95;
S_Brazil["bynavn"] = "Rio de Janeiro";
S_France["x"] = 459.1;
S_France["y"] = 403.9;
S_France["bynavn"] = "Paris";
S_China["x"] = 716.2;
S_China["y"] = 143.3;
S_China["bynavn"] = "Beijing";
S_Australia["x"] = 809.35;
S_Australia["y"] = 414.95;
S_Australia["bynavn"] = "Sydney";
// ----------------------------------------------------
airportDict["USA"] = S_USA;
airportDict["Norway"] = S_Norway;
airportDict["South Africa"] = S_South_Africa;
airportDict["Brazil"] = S_Brazil;
airportDict["France"] = S_France;
airportDict["China"] = S_China;
airportDict["Australia"] = S_Australia;
for (var k:Object in airportDict)
{
var value = airportDict[k];
var key = k;
startList.addItem({label:key, data:key});
sluttList.addItem({label:key, data:key});
var airport:Airport = new Airport(key,airportDict[key]["bynavn"]);
airport.koordinater(airportDict[key]["x"], airportDict[key]["y"]);
bg_image.addChild(airport);
}
// --------------------------------------------
// --------------------------------------------
// -----------------------------------------------
}
private function startDragging(mev:MouseEvent):void
{
spImage.startDrag();
}
private function stopDragging(mev:MouseEvent):void
{
spImage.stopDrag();
}
private function zoom(mev:MouseEvent):void
{
if ((!mev.shiftKey)&&(!mev.ctrlKey))
{
return;
}
if ((mev.shiftKey)&&(mev.ctrlKey))
{
return;
}
externalCenter = new Point(spImage.mouseX,spImage.mouseY);
internalCenter = new Point(bg_image.mouseX,bg_image.mouseY);
if (mev.shiftKey)
{
bg_image.scaleX = Math.max(scaleFactor*bg_image.scaleX, minScale);
bg_image.scaleY = Math.max(scaleFactor*bg_image.scaleY, minScale);
}
if (mev.ctrlKey)
{
trace("Minscale: ", maxScale)
trace("Returned: ", 1/scaleFactor*bg_image.scaleY)
bg_image.scaleX = Math.min(1/scaleFactor*bg_image.scaleX, maxScale);
bg_image.scaleY = Math.min(1/scaleFactor*bg_image.scaleY, maxScale);
}
mat = this.transform.matrix.clone();
MatrixTransformer.matchInternalPointWithExternal(mat,internalCenter,externalCenter);
bg_image.transform.matrix = mat;
}
private function keyHandler(ke:KeyboardEvent):void
{
mcIn.x = spImage.mouseX;
mcIn.y = spImage.mouseY;
mcOut.x = spImage.mouseX;
mcOut.y = spImage.mouseY;
mcIn.visible = ke.ctrlKey;
mcOut.visible = ke.shiftKey;
if (ke.ctrlKey || ke.shiftKey)
{
Mouse.hide();
}
else
{
Mouse.show();
}
}
private function reise(evt:MouseEvent):void
{
var new_flight:Flight = new Flight(airportDict[startList.selectedItem.label]["x"],airportDict[startList.selectedItem.label]["y"],airportDict[sluttList.selectedItem.label]["x"],airportDict[sluttList.selectedItem.label]["y"]);
bg_image.addChild(new_flight);
}
private function mouseCoordinates(event: MouseEvent):void
{
// these are the x and y relative to the object
var localMouseX:Number = bg_image.mouseX;
var localMouseY:Number = bg_image.mouseY;
trace("Local coordinates: ", localMouseX, localMouseY);
// these are the x and y relative to the whole stage
var stageMouseX:Number = event.stageX;
var stageMouseY:Number = event.stageY;
trace("Global coordinates: ", stageMouseX, stageMouseY);
}
}
}
Image class:
package {
import flash.display.Sprite;
import flash.display.MovieClip;
public class Image extends Sprite
{
public function Image(y_:Number, x_:Number)
{
this.y = y_
this.x = x_
}
}
}
You don't have minScale declared, neither maxScale.
bg_image should be declared as Sprite, otherwise Compiler Error: Implicit coercion...
`
public var bg_image:Sprite;
As your image is very small, you may want to add your listener to the stage, and not the image, it would be very dificult to click in such a small image.
Also, here is your example working with MOUSE_WHEEL, instead of Click + Ctrl / Shift
stage.addEventListener(MouseEvent.MOUSE_WHEEL, zoom);
private function zoom(mev:MouseEvent):void
{
mev.delta > 0 ?
bg_image.scaleX = bg_image.scaleY = Math.max(scaleFactor * bg_image.scaleX, minScale) :
bg_image.scaleX = bg_image.scaleY = Math.min(1/scaleFactor * bg_image.scaleX, maxScale) ;
}

AS3 > Starting class on certain frame? TypeError :Error #1006

Im trying to create a simple memory game i have 3 frames Intro ,Main Game , End however every time i click the "start button" to jump to frame 2 i keep getting this error;
TypeError: Error #1006: Play_AnimalCardGame is not a function.
at AnimalCardGame/frame2()
at flash.display::MovieClip/gotoAndStop()
at AnimalCardGame/startGame()
My .AS
package{
import flash.display.*;
import flash.events.*;
import flash.utils.getTimer;
public class Play_AnimalCardGame extends MovieClip
{
private static const boardWidth:uint =4;
private static const boardHeight:uint =3;
private static const cardVSpace:Number=100;
private static const cardHSpace:Number=15;
private static const offSetX:Number=115;
private static const offSetY:Number=155;
public function Play_AnimalCardGame ():void
{
var cardDeck:Array = new Array();
for ( var i:uint=0;i<boardWidth*boardHeight/2;i++){
cardDeck.push(i);
cardDeck.push(i);
}
for(var x:uint=0; x<boardWidth ; x++){
for(var y:uint=0; y<boardHeight;y++){
var aCard:Card = new Card();
aCard.stop();
aCard.x = x*offSetX+cardVSpace;
aCard.y = y*offSetY+cardHSpace;
var randomCard:uint = Math.floor(Math.random()*cardDeck.length);
aCard.cardface= cardDeck[randomCard];
cardDeck.splice(randomCard,1);
aCard.gotoAndStop(1);
aCard.addEventListener(MouseEvent.CLICK,clickCard);
addChild(aCard);
cardLeft++;
}
}
}
private var firstPick:Card;
private var secondPick:Card;
private var cardLeft;
private static const pointHit:int =100;
private static const pointMiss:int = -5;
private var startscore =0;
var startTime:uint;
var time:uint;
public function clickCard(event:MouseEvent){
var pickedCard:Card = (event.currentTarget as Card);
if(firstPick == null){
firstPick =pickedCard;
firstPick.gotoAndStop(pickedCard.cardface+2);
}
else if (firstPick ==pickedCard){
firstPick.gotoAndStop(1);
firstPick=null;
}
else if (secondPick ==null){
secondPick= pickedCard;
secondPick.gotoAndStop(pickedCard.cardface+2);
if (firstPick.cardface == secondPick.cardface){
startscore +=pointHit;
cardLeft-=2;
removeChild(firstPick);
removeChild(secondPick);
txtscore.text= String(startscore);
firstPick = null;
secondPick=null;
}
else{
firstPick.gotoAndStop(1);
secondPick.gotoAndStop(1);
startscore +=pointMiss;
txtscore.text= String(startscore);
secondPick=null;
firstPick = pickedCard;
firstPick.gotoAndStop(pickedCard.cardface+2);
}
}
if(cardLeft==0){
gotoAndStop("gameover");
}
}
public function showTimer(event:Event)
{
startTime = getTimer();
time=0;
time = getTimer()- startTime;
txtTime.text = clockTime(time);
}
public function clockTime(ms:int){
var seconds:int = Math.floor(ms/1000);
var minutes:int = Math.floor(seconds/60);
seconds -=minutes *60;
var timeString:String = minutes+":"+String(seconds+100).substr(1,2);
return timeString;
}
}
From what i can there are no problems but then again in still only learning
It looks like you've defined the class name as
Play_AnimalCardGame
but then you define the constructor as
AnimalCardGame
Start by setting the constructor name to the same as the class name

actionscript 3 new game btn in main menu not working

I have a problem with my game.
When i played level 1 and i return to my main menu, the button new game doesn't work anymore.
Does anyone know what could be the problem?
this is what i have in my main menu as:
package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
import HomeTitel;
import InstBtn;
import NieuwBtn;
public class Hoofdmenu extends MovieClip
{
private var homeTitel:HomeTitel;
private var instBtn:InstBtn;
private var nieuwBtn:NieuwBtn;
private var inst:Instructions;
private var level1:Level1;
public function Hoofdmenu():void
{
placeHomeTitel();
placeInstructionsBtn();
placeNieuwBtn();
}
private function placeHomeTitel():void
{
homeTitel = new HomeTitel();
addChild(homeTitel);
homeTitel.x = 275;
homeTitel.y = 20;
}
private function placeInstBtn():void
{
instBtn = new InstBtn();
addChild(instBtn);
instBtn.x = 275;
instBtn.y = 225;
instBtn.addEventListener(MouseEvent.CLICK, gotoInstructions);
}
private function gotoInstructions(event:MouseEvent)
{
inst = new Instructoins();
addChild(inst);
}
private function placeNewBtn():void
{
newBtn = new NewBtn();
addChild(newBtn);
newBtn.x = 275;
newBtn.y = 175;
newBtn.addEventListener(MouseEvent.CLICK, gotoLevel1);
}
private function gotoLevel1(event:MouseEvent):void
{
level1 = new Level1();
addChild(level1);
}
}
}
this is what i have in my level1 as:
package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.utils.Timer;
import flash.events.TimerEvent;
import L1Achtergrond;
import L1Titel;
import MenuBtn;
import Sun;
import Min;
import GameOver;
import WellDone;
import VolgLevel;
import HoofdmenuBtn;
import Opnieuw;
public class Level1 extends MovieClip
{
private var back:L1Achtergrond;
private var titel:L1Titel;
private var menu:MenuBtn;
private var sun:Sun;
private var aantalSun:int = 5;
private var counter:int;
private var sunArray:Array = new Array();
private var timer:Timer;
private var min:Min;
private var gameover:GameOver;
private var welldone:WellDone;
private var volglevel:VolgLevel;
private var opn:Opnieuw;
private var hoofdBtn:HoofdmenuBtn;
private var level1:Level1;
private var level2:Level2;
private var hoofdmenu:Hoofdmenu;
public function Level1():void
{
back = new L1Achtergrond();
addChild(back);
placeTitel();
timer = new Timer(3000,1);
timer.addEventListener(TimerEvent.TIMER_COMPLETE, startLevel1);
timer.start();
}
private function placeTitel():void
{
titel = new L1Titel();
addChild(titel);
titel.x = 275;
titel.y = 150;
}
private function startLevel1(event:TimerEvent):void
{
for (counter = 0; counter < aantalSun; counter++)
{
sun = new Sun();
sunArray.push(sun);
addChild(sun);
sun.addEventListener(MouseEvent.CLICK, checkSun);
}
min = new Min();
addChild(min);
min.x = 275;
min.y = 30;
min.play();
min.width = 40;
min.height = 20;
timer = new Timer(20000,1);
timer.addEventListener(TimerEvent.TIMER_COMPLETE, gameOver);
timer.start();
menu = new MenuBtn();
addChild(menu);
menu.x = 510;
menu.y = 380;
menu.addEventListener(MouseEvent.CLICK, gotoHoofdmenu);
}
private function checkSun(event:MouseEvent):void
{
aantalSun--;
if (aantalSun == 0)
{
wellDone();
timer.stop();
}
}
public function wellDone():void
{
removeChild(menu);
removeChild(min);
welldone = new WellDone();
addChild(welldone);
welldone.x = 275;
welldone.y = 150;
volglevel = new VolgLevel();
addChild(volglevel);
volglevel.x = 300;
volglevel.y = 250;
volglevel.addEventListener(MouseEvent.CLICK, gotoLevel2);
hoofdBtn = new HoofdmenuBtn();
addChild(hoofdBtn);
hoofdBtn.x = 95;
hoofdBtn.y = 250;
hoofdBtn.addEventListener(MouseEvent.CLICK, gotoHoofdmenuW);
}
private function gameOver(event:TimerEvent):void
{
//timer.stop();
removeChild(min);
removeChild(menu);
for (counter = 0; counter < sunArray.length; counter++)
{
removeChild(sunArray[counter]);
}
gameover = new GameOver();
addChild(gameover);
gameover.x = 275;
gameover.y = 150;
opn = new Opnieuw();
addChild(opn);
opn.x = 300;
opn.y = 250;
opn.addEventListener(MouseEvent.CLICK, level1Opn);
hoofdBtn = new HoofdmenuBtn();
addChild(hoofdBtn);
hoofdBtn.x = 95;
hoofdBtn.y = 250;
hoofdBtn.addEventListener(MouseEvent.CLICK, gotoHoofdmenuG);
}
private function level1Opn(event:MouseEvent):void
{
removeChild(gameover);
removeChild(opn);
removeChild(hoofdBtn);
removeChild(back);
level1 = new Level1();
addChild(level1);
}
private function gotoHoofdmenu(event:MouseEvent):void
{
timer.stop();
removeChild(min);
removeChild(menu);
removeChild(back);
for (counter = 0; counter < sunArray.length; counter++)
{
removeChild(sunArray[counter]);
}
}
private function gotoHoofdmenuW(event:MouseEvent):void
{
removeChild(back);
removeChild(welldone);
removeChild(hoofdBtn);
removeChild(volglevel);
}
private function gotoHoofdmenuG(event:MouseEvent):void
{
removeChild(back);
removeChild(gameover);
removeChild(hoofdBtn);
removeChild(opn);
}
private function gotoLevel2(event:MouseEvent):void
{
removeChild(back);
removeChild(volglevel);
removeChild(hoofdBtn);
removeChild(welldone);
level2 = new Level2();
addChild(level2);
}
}
}
I think you should rebuild/redesign the structure of your game.
Now, your code does few strange things:
in your Main class: everytime you call function gotoLevel1 you create a new instance of Level1
in your Level1 class in the function level1Opn you create another instance of 'Level1' and you add it inside Level1 - quite a mess.
This isn't just small code tweak - you should rebuild it quite significantly.
Seems like you never remove level1 from your menu. Even though you remove all children from Level 1, the movieclip will still exist and be on top of your menu.
I would recommend reading though this tutorial, as it will teach you some basic skills about structuring your code, and specific game development features (sound, preloading, saving things in cookies): http://gamedev.michaeljameswilliams.com/2008/09/17/avoider-game-tutorial-1/

Trouble with null reference on stage properties in AS3

I am making a website in Flash, coded in flashbuilder. Whenever I try to export my code I get the same error again and again (TypeError = see below).
I think the problem has something to do with the stage of my project. Whenever I change the var stageMiddenX = (stage.stageWidth / 2); into var stageMiddenX = 512;, the code works. but I wan't the var to be dynamic.
TypeError
Error #1009: cannot access a property or method of a null object reference at main()
package {
import flash.display.MovieClip;
public class main extends MovieClip{
var stageMiddenX = (stage.stageWidth / 2);
var stageMiddenY = (stage.stageHeight / 2);
private var object1:Object1 = new Object1();
private var object2:Object2 = new Object2();
private var object3:Object3 = new Object3();
}
}
The issue here is that stage is not yet available at the time you are requesting it.
You'll want to wait until the Event.ADDED_TO_STAGE event is fired before attempting to acccess stage.
package {
import flash.display.MovieClip;
public class main extends MovieClip{
private var object1:Object1 = new Object1();
private var object2:Object2 = new Object2();
private var object3:Object3 = new Object3();
private var stageMiddenX:Number;
private var stageMiddenY:Number;
public function main(){
if(stage) init(null);
else addEventListener(Event.ADDED_TO_STAGE, init)
}
private function init(e:Event):void {
removeEventListener(Event.ADDED_TO_STAGE, init);
stageMiddenX = (stage.stageWidth / 2);
stageMiddenY = (stage.stageHeight / 2);
}
}
}
Put the stuff accessing stage into a constructor (assuming this is your document class)..
package
{
import flash.display.MovieClip;
public class main extends MovieClip
{
public var stageMiddenX:int;
public var stageMiddenY:int;
private var object1:Object1 = new Object1();
private var object2:Object2 = new Object2();
private var object3:Object3 = new Object3();
public function main()
{
stageMiddenX = stage.stageWidth / 2;
stageMiddenY = stage.stageHeight / 2;
}
}
}

tweenlite not working with bitmaps?

I have the following problem when I try to use TweenLite with a Bitmap:
I get strange error messages when applying TweenLite to a Bitmap (tempScore.bitmap). GetBounds works. The bitmap has transparency. Does anyone have an idea why it doesn't work? Any help appreciated. Thanks.:)
When using a getBounds-Method I get this:
tempScore.bitmap.getBounds(this)(x=2.35, y=-0.45, w=25, h=18)
This is the 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 (blitting-method).
tempScore is a Score-object. The Score object is based on a BasicBlitArrayObject. Otherwise this object extends an EventDispatcher. I hope this little info helps.
This is the scoreManager which manages the look and properties of tempScore:
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);
}
}
}
Here is some code of the BasicBlitArrayObject (tempScore rests upon that (i.e. Score-object):
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;
}
}
}
I think the problem is simple, but the resolution is not. The objects you are trying to transform are blitted. So they are not added to the stage. So the object's stage property is null.
I suspect that the TransformAroundPoint plugin is trying to use the object's stage property, and that is throwing a null object error your are seeing.
To see a simple example of this, make a very simple file.
Create two bitmaps, add one to the stage, and don't add the other.
Apply the tween to the stage instance, it will work.
Then apply the tween to the off-stage instance, and you should get the same error you get in the game.
What you will need to do instead is handle the transform yourself. Instead of using TweenLite to rotate around a point, do it yourself.
Fortunately Stack Overflow already has a great thread on that topic!
Rotate around a point that is not (0,0)