Invalid BitMapdata Error #2015 - actionscript-3

private static var tileDir:String;
public static var tileImage:BitmapData;
private static var loader:Loader;
public static var tileReady:EventDispatcher = new EventDispatcher();
public static var tileNum_perRow:Number = 3;
public static var select:selector;
public var tileNum:Number = 0;
public var setBack:Number = 0;
public var tileState:String;
public var tCol:Number;
public var tRow:Number;
private var tWidth:int = 30;
private var tHeight:int = 30;
private var tImage:BitmapData;
private var canvas:Bitmap;
private var p:Point;
private var r:Rectangle;
public function Tile():void
{
var tempImage:BitmapData = tileImage;
r = new Rectangle(0,0,30,30);
p = new Point(0,0);
tImage = new BitmapData(30,30);
tImage.copyPixels(tempImage,r,p);
}
And I get the following error:
ArgumentError: Error #2015: Invalid BitmapData.
It tends to happen when I copy the pixels. I dont know why.
tileImage;
tileImage is valid, I've used the variable in the code below and it works. But above doesnt. Don't know why. Anyone have any clues?
this.graphics.beginBitmapFill(tileImage);
this.graphics.drawRect(60, 0,tWidth ,tHeight );

Nevermind, I figure a better solution
theMatrix.translate(30,0);
this.graphics.beginBitmapFill(tileImage,theMatrix);
//this.graphics.drawRect(0, 0,tWidth ,tHeight );
this.graphics.endFill();
using the theMatrix.translates give you the ability to choose what part of the tile you want, without effecting the position of the sprite

Related

A conflict exists with inherited definition flash.display:MovieClip.isPlaying in namespace public

errore (private var isPlaying:Boolean;),i want paly more mp3 file for my project.help me.
Here's my code starts:
public class PlayerClass extends MovieClip
{
private var urlLoader:URLLoader;
private const xmlPath:String = "playlist.xml";//xml path
private var xml:XML;
private var songs:Array;// array for song paths
private var titles:Array;// array for song titles
private var currentSong:Number = 0;
private var sound:Sound;
private var context:SoundLoaderContext;
private var channel:SoundChannel;
private var isPlaying:Boolean;
private var isStopped:Boolean;
private var songPosition:int = 0;
}

[No debug Flash player connection request]

I have a Problem with away 3d.I wanted to create an application and it was working fine till I had embedded 5 images in my program but as soon as I embed more than 5 images the flash develop stops responding [No debug Flash player connection request] showing me this message.Is it the problem with the number of images or should I do something else to include these images.
[Embed(source="assets1/b1 copy.png")]
private var EarthImage:Class;
private var earth:Bitmap = new EarthImage();
[Embed(source="assets1/balls.jpg")]
private var bac:Class;
private var bm:Bitmap = new bac();
[Embed(source="assets1/1.png")]
private var bac1:Class;
private var bm1:Bitmap = new bac1();
[Embed(source="assets1/2.png")]
private var bac2:Class;
private var bm2:Bitmap = new bac2();
[Embed(source="assets1/3.png")]
public var bac3:Class;
public var bm3:Bitmap = new bac3();
[Embed(source="assets1/4.png")]
public var bac4:Class;
public var bm4:Bitmap = new bac4();
[Embed(source="assets1/5.png")]
public var bac5:Class;
public var bm5:Bitmap = new bac5();
[Embed(source="assets1/6.png")]
public var bac6:Class;
public var bm6:Bitmap = new bac6();
[Embed(source="assets1/7.png")]
public var bac7:Class;
public var bm7:Bitmap = new bac7();
[Embed(source="assets1/8.png")]
public var bac8:Class;
public var bm8:Bitmap = new bac8();
[Embed(source="assets1/9.png")]
public var bac9:Class;
public var bm9:Bitmap = new bac9();
[Embed(source="assets1/10.png")]
public var bac10:Class;
public var bm10:Bitmap = new bac10();
[Embed(source="assets1/11.png")]
public var bac11:Class;
public var bm11:Bitmap = new bac11();
[Embed(source="assets1/12.png")]
public var bac12:Class;
public var bm12:Bitmap = new bac12();
[Embed(source="assets1/13.png")]
public var bac13:Class;
public var bm13:Bitmap = new bac13();
[Embed(source="assets1/14.png")]
public var bac14:Class;
public var bm14:Bitmap = new bac14();
[Embed(source="assets1/15.png")]
public var bac15:Class;
public var bm15:Bitmap = new bac15();
[Embed(source="assets1/16.png")]
public var bac16:Class;
public var bm16:Bitmap = new bac16();
[Embed(source="assets1/17.png")]
public var bac17:Class;
public var bm17:Bitmap = new bac17();
[Embed(source="assets1/18.png")]
public var bac18:Class;
public var bm18:Bitmap = new bac18();
[Embed(source="assets1/19.png")]
public var bac19:Class;
public var bm19:Bitmap = new bac19();
[Embed(source="assets1/20.png")]
public var bac20:Class;
public var bm20:Bitmap = new bac20()
This is the code I am using to embed the images into the application.

Actionscript 3: Create dictionary inside class?

I'm trying to transform my actionscript 3 code from the timeline, which I previously used, to packages.
I need to define some dictionaries in the beginning of the code.
But when running the following code inside my class, actionscript returns an error.
public var S_USA:Dictionary = new Dictionary();
S_USA["x"] = -299;
S_USA["y"] = -114;
S_USA["bynavn"] = "New York";
This is the error: "1120: Access of undefined property S_USA.
EDIT: Posting the entire code:
package
{
import fl.motion.MatrixTransformer;
import flash.display.MovieClip;
import flash.utils.Dictionary;
import flash.display.Shape;
import fl.transitions.Fly;
import fl.motion.MatrixTransformer;
import flash.events.MouseEvent;
import flash.display.Sprite;
import flash.events.KeyboardEvent;
import flash.geom.Matrix;
import flash.geom.Point;
import flash.ui.Mouse;
import flash.text.TextField;
import flash.display.SimpleButton;
import fl.controls.List;
public class Main extends MovieClip
{
public static var bg_width = 980;
public static var bg_height = 541;
public var spImage:Sprite;
public var mat:Matrix;
public var mcIn:MovieClip;
public var mcOut:MovieClip;
public var externalCenter:Point;
public var internalCenter:Point;
public var scaleFactor:Number = 0.8;
public var minScale:Number = 0.25;
public var maxScale:Number = 10.0;
/*public static var startList:List;
public static var sluttList:List;*/
public var bynavntxt:TextField;
public var intervall:TextField;
public var create_route:SimpleButton;
public var confirm_button:SimpleButton;
public var beregn_tid:SimpleButton;
public static var S_Norway:Dictionary = new Dictionary();
S_Norway["x"] = -60;
S_Norway["y"] = -183;
S_Norway["bynavn"] = "Oslo";
public static var S_Australia:Dictionary = new Dictionary();
S_Australia["x"] = 307;
S_Australia["y"] = 153;
S_Australia["bynavn"] = "Sydney";
public static var S_China:Dictionary = new Dictionary();
S_China["x"] = 239;
S_China["y"] = -98;
S_China["bynavn"] = "Beijing";
public static var S_South_Africa:Dictionary = new Dictionary();
S_South_Africa["x"] = -26;
S_South_Africa["y"] = 146;
S_South_Africa["bynavn"] = "Cape Town";
public static var S_Brazil:Dictionary = new Dictionary();
S_Brazil["x"] = -210;
S_Brazil["y"] = 73;
S_Brazil["bynavn"] = "Rio de Janeiro";
public static var S_USA:Dictionary = new Dictionary();
S_USA["x"] = -299;
S_USA["y"] = -114;
S_USA["bynavn"] = "New York";
public static var S_France:Dictionary = new Dictionary();
S_France["x"] = -79;
S_France["y"] = -135;
S_France["bynavn"] = "Paris";
// ------------------------------------------------------
public static var Flyplasser:Dictionary = new Dictionary();
Flyplasser["USA"] = S_USA;
Flyplasser["Norway"] = S_Norway;
Flyplasser["South Africa"] = S_South_Africa;
Flyplasser["Brazil"] = S_Brazil;
Flyplasser["France"] = S_France;
Flyplasser["China"] = S_China;
Flyplasser["Australia"] = S_Australia;
public function Main()
{
// ------------------------------------
startList:List = new List();
sluttList:List = new List();
bynavntxt:TextField = new TextField() ;
intervall:TextField = new TextField() ;
create_route:SimpleButton = new SimpleButton() ;
confirm_button:SimpleButton = new SimpleButton() ;
beregn_tid:SimpleButton = new SimpleButton() ;
this.addChild(startList);
this.addChild(sluttList);
this.addChild(bynavntxt);
this.addChild(intervall);
this.addChild(create_route);
this.addChild(confirm_button);
this.addChild(beregn_tid);
// -----------------------------------------
// We use the ctrl and shift keys to display the two different cursors that were created on the stage.
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyHandler);
stage.addEventListener(KeyboardEvent.KEY_UP, keyHandler);
this.addEventListener(MouseEvent.CLICK, mouseCoordinates);
trace("Main spawned");
// --------------------
this.width = bg_width;
this.height = bg_height;
// --------------------
for (var k:Object in Flyplasser)
{
var value = Flyplasser[k];
var key = k;
trace(key);
startList.addItem({label:key, data:key});
sluttList.addItem({label:key, data:key});
var airport:flyplass = new flyplass(key,Flyplasser[key]["bynavn"]);
airport.koordinater(Flyplasser[key]["x"], Flyplasser[key]["y"]);
this.addChild(airport);
}
var mcOut = new OutCursorClip();
this.addChild(mcOut);
var mcIn = new InCursorClip();
this.addChild(mcIn);
startList = new List();
this.addChild(startList)
sluttList = new List();
this.addChild(sluttList)
bynavntxt = new TextField;
this.addChild(bynavntxt)
intervall = new TextField;
this.addChild(intervall)
create_route = new SimpleButton;
this.addChild(create_route)
confirm_button = new SimpleButton;
this.addChild(confirm_button)
beregn_tid = new SimpleButton;
this.addChild(beregn_tid)
Are you setting this data inside Constructor or function?
EDIT:
Hm, where to start...
1) You know that the trick with static is not gonna work if you'll create more than 1 instance of class? In this case if you have only 1 Main class it's gonna work, but omg... Imho it's not nice to store data in static vars...
2) If you already declared:
public var bynavntxt:TextField;
public var intervall:TextField;
later just do
bynavntxt = new TextField() ;
intervall = new TextField() ;
no need for type in there.
3) Later in Main you have something like:
var mcOut = new OutCursorClip();
this.addChild(mcOut);
var mcIn = new InCursorClip();
this.addChild(mcIn);
Why are you declaring new variables with same name but without Type?
Waaaaaay up you have:
public var mcIn:MovieClip;
public var mcOut:MovieClip;
so those variables are already declared. By declaring them once again you are creating local ones. Beware!! The ones from the top would be null after that.
1) Fill the dictionary inside the Constructor (I seen by comments you have done this already).
2) you have already assigned type to bynavntxt with public var bynavntxt:TextField; you should not be doing it again with bynavntxt:TextField = new TextField(); just bynavntxt= new TextField(); will do.
This is the same with all other variables on similar type.
3) Make sure this class is going to be your "Document Class"/"Compiled Class" otherwise you will not have access to the 'stage' variable yet. To make sure you will have access to the stage variable you can always do:
/* Inside Constructor */
addEventListener(Event.ADDED_TO_STAGE, _onAddedToStage);
/* Outside Constructor */
private function _onAddedToStage(e:Event):void
{
removeEventListener(Event.ADDED_TO_STAGE, _onAddedToStage);
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyHandler);
stage.addEventListener(KeyboardEvent.KEY_UP, keyHandler);
}
Again, if this is going to be the compiled class, this can be skipped.

AS3 object array to class

I am new and having an issue with the use of classes in as3.
I have created an array of objects in my main timeline
function badPlayer()
{
var bads:Array = new Array();
for (var i=0; i<5; i++)
{
var mc = new bman();
mc.name=["mc"+i];
bads.push(mc);
_backGround.addChild(mc);
mc.x = 100;
mc.y = 100;
trace (bads);
Baddies(_backGround.mc); //here I am trying to export mc to my class
}
}
Here is a snip-it from my class. My trace statement wont even output.
public class Baddies extends MovieClip
{
private var pistolSound:pistolShot = new pistolShot();
//private var mc = new mc();
private var _rotateSpeedMax:Number = 2;
private var _gravity:Number = .68;
private var _bulletSpeed:Number = 2;
private var _maxDistance:Number = 200;
private var _reloadSpeed:Number = 500; //milliseconds
private var _barrelLength:Number = 20;
private var _bulletSpread:Number = 5;
private var _isLoaded:Boolean = true;
private var _isFiring:Boolean = true;
private var _endX:Number;
private var _endY:Number;
private var _startX:Number;
private var _startY:Number;
private var _reloadTimer:Timer;
private var _bullets:Array = [];
private var _gun:MovieClip;
private var _enemy:MovieClip;
private var _yx:Number;
private var _yy:Number;
private var _pcos:Number;
private var _psin:Number;
private var _trueRotation:Number;
public function Baddies()
{
trace("working");
stage.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
}
Basically I am trying to create several bad guys (bman) and have the same code apply to each of them. I have also tried to change the linkage name of bman to Baddies with no success.
There are a few thing that are very wrong with this code.
Baddies(_backGround.mc); //here I am trying to export mc to my class
This is a typecast, as already stated in the comments. By the way Baddies isn't a good name, because it plural. You probably want to create a new bad guy, which would be done with this line:
var baddie = new Baddies();
Now your constructor uses the stage variable. This won't work because the object isn't on the stage, therefore stage is null (it may works if you drag and drop an instance to the stage in the editor). So before using the stage you actually need to add the object to the stage:
public function Baddies() {
trace("new baddie created");
}
public function init(mc:MovieClip) {
mc.addChild(this); // display this baddie
trace("working");
stage.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
}
And in the badPlayer function:
var baddie = new Baddies();
baddie.init(_backGround);

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)