I have two classes, one class declares the static arrays (3 of them in total and they all store objects) and the other changes the value of the objects in these arrays, such as the x value of a character or the background objects.
The problem is that, the other class that changes the value of these static array objects only manages to work with only ONE array which is the Main.Level1rray[0] meanwhile the Main.Okechurray[0] produces an error saying TypeError: Error #1010: A term is undefined and has no properties. when I try to change the x value (which works with the other array but not this one. which is very weird).
Look at the code and you will see how it looks so you can help me understand the error
(THIS IS WEIRD BECAUSE IT WORKS FOR 1/2 OF THE ARRAYS)
P.S. I put these arrays into public static arrays so that other classes could interact with them.
Class That Declares The Public Static Arrays:
package {
import flash.display.MovieClip;
import flash.events.Event;
public class Main extends MovieClip {
public static var Okchurray:Array = new Array(); //***HERE****
public static var Banditrray:Array = new Array(); //***HERE****
public static var Level1rray:Array = new Array(); //***HERE****
public static var outOfBoundsL:Boolean;
public static var outOfBoundsR:Boolean;
public function Main() {
// constructor code
stage.addEventListener(Event.ENTER_FRAME, loop)
//parent.addChild(Okchurray[0]);
MovieClip(root).objtxt.text = "Objective: Get Your Passport.";
}
function loop(e:Event){
//if okechuku is left or right of the screen stop him and let him walk
LeftRightTest();
//check to see if bandit and okochuku are touching
HitTestOknBan();
trace(Main.Okchurray.length);
//if ((Arg[0].x > 500) || (Arg[0].x < 100)){outOfBounds=false;}
}
function LeftRightTest(){
//Holler at bob the builder this is broken.
if ((Main.Okchurray[0].x > 500) && (Okechuku.D)){ MainLevel.rightSide=true; outOfBoundsR=true;} else {MainLevel.rightSide=false; outOfBoundsR=false;}
if ((Main.Okchurray[0].x < 100) && (Okechuku.A)){ MainLevel.leftSide=true; outOfBoundsL=true;} else {MainLevel.leftSide=false; outOfBoundsL=false;}
//***HERE****
}
function HitTestOknBan(){
if((Main.Banditrray[0]).hitTestObject(Main.Okchurray[0])){
trace("gotcha");
Main.Okchurray[0].x = 10
}
}
} }
Class That Changes The x Value of These Public Static Arrays:
package {
import flash.display.MovieClip;
import flash.events.Event;
public class Bandits extends MovieClip {
public static var gotPp:Boolean;
public static var chase:Boolean;
public function Bandits() {
// constructor code
addEventListener(Event.ENTER_FRAME, loopThis)
MovieClip(parent).Banditrray.push(this);
}
function loopThis(e:Event){
moveFoward();
beginChase();
}
function beginChase(){
if((gotPp) && (MainLevel.rightSide)){
chase=true;
MovieClip(root).objtxt.text = "Objective: Outrun the bandit before he takes your passport!";
}
if((chase) && (x < 200)){x+=2}
if((MainLevel.toofarR) && (chase)){
removeEventListener(Event.ENTER_FRAME, loopThis);
MovieClip(parent).removeChild(this)
Main.Level1rray[0].x=1600.35; //***HERE****
Main.Okchurray[0].x=10; //***HERE****
}
}
function moveFoward(){
if((MainLevel.toofarR) && (chase) || (!Okechuku.Space) && (chase) || (Okechuku.A) && (chase)){
x+=6;
}
}
}
}
Okchurraysomewhere?Okechurrayin one place, andOkchurrayin another.