I have been trying to fix the above error since yesterday late into the night.
Today i tried again for many hours. I learned a great deal and understand a lot more. I found some things along the way and fixed them, unfortunatly the error persisted.
I now know for example
that the above error indicates that one of the objects being targeted by my code is out of scope.
Caused possibly by:
-
It being declared but not instantiated
-
It doesn’t have an instance name (or the instance name is misspelled)
-
It does not exist in the frame where that code is trying to talk to it
-
It is animated into place but is not assigned instance names in every keyframe for it
-
It is one of two or more consecutive keyframes of the same objects with no name (or a different name) assigned in the preceding frame(s).
This is the error line where it goes wrong:
if (back.collisions.hitTestPoint(player.x + leftBumpPoint.x,player.y + leftBumpPoint.y,true))
So it has to be something with back or collosions…
-
I checked and it’s not a misspeled instance
BTW back is a background movieclip with Back instance and it contains the collisions image with instance Collisions -
it is being declared (but possibly not right)
-
Could be the cause. frame 1 is the preloader. frame 2 is the menu with a button to start code cat.as. Frame 3 contains the game
-
it only exists on one keyframe so it isn’t mistake number 4
-
it only exists on one keyframe so it isn’t mistake number 5
So it’s most likely number 3.
What i think happens is that i click on the button and it immediatly wants to run cat.as before going to frame 3. How should i solve this. I’m thinking of placing the game on frame 2 but offscreen.
I would very much like feedback on this, please. Thanks
My code: EDIT: i gave the var public
package
{
import flash.display.MovieClip;
import flash.events.*;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import flash.geom.Point;
public class Cat extends MovieClip
{
public var leftPressedfBoolean = false;
public var rightPressed:Boolean = false;
public var upPressed:Boolean = false;
public var downPressed:Boolean = false;
public var leftBumping:Boolean = false;
public var rightBumping:Boolean = false;
public var upBumping:Boolean = false;
public var downBumping:Boolean = false;
public var leftBumpPoint:Point = new Point(-30,-55);
public var rightBumpPoint:Point = new Point(30,-55);
public var upBumpPoint:Point = new Point(0,-120);
public var downBumpPoint:Point = new Point(0,0);
public var scrollX:Number = 0;
public var scrollY:Number = 500;
public var xSpeed:Number = 0;
public var ySpeed:Number = 0;
public var speedConstant:Number = 4;
public var frictionConstant:Number = 0.9;
public var gravityConstant:Number = 1.8;
public var jumpConstant:Number = -35;
public var maxSpeedConstant:Number = 18;
public var doubleJumpReady:Boolean = false;
public var upReleasedInAir:Boolean = false;
public var keyCollected:Boolean = false;
public var doorOpen:Boolean = false;
public var currentLevel:int = 1;
public var animationState:String = "idle";
public var bulletList:Array = new Array();
public var enemyList:Array = new Array();
public var bumperList:Array = new Array();
public var player:Player;
public var back:Back;
public var sky:Sky;
public var collisions:Collisions;
public var visuals:Visuals;
public var other:Other;
public var doorKey:DoorKey;
public function Cat()
{
addEventListener(Event.ADDED_TO_STAGE, init);
}
public function init(e:Event):void
{
player = new Player();
back = new Back();
sky = new Sky();
visuals = new Visuals();
other = new Other();
collisions = new Collisions();
doorKey = new DoorKey();
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
stage.addEventListener(Event.ENTER_FRAME, loop);
addEnemiesToLevel1();
addBumpersToLevel1();
}
public function addEnemiesToLevel1():void
{
addEnemy(620, -115);
addEnemy(900, -490);
addEnemy(2005, -115);
addEnemy(1225, -875);
}
public function addBumpersToLevel1():void
{
addBumper(500, -115);
addBumper(740, -115);
}
public function loop(e:Event):void
{
if (back.collisions.hitTestPoint(player.x + leftBumpPoint.x,player.y + leftBumpPoint.y,true))
{
//trace("leftBumping");
leftBumping = true;
}
else
{
leftBumping = false;
}
Add this before your if statement to see which item is missing: