1

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;
        }

    }

}

}

4
  • Do you stuff a thing in Okchurray somewhere? Commented Jul 1, 2014 at 14:13
  • Also, when I've tried to edit your post, I've discovered a potential typo: you say Okechurray in one place, and Okchurray in another. Commented Jul 1, 2014 at 14:16
  • The LeftRightTest() seems to execute before you're adding something to Main.Okchurray. I can't figure why you need arrays though. You're not looping through the arrays anywhere from what I see, so why not use plain movie clips? Commented Jul 1, 2014 at 14:36
  • @CristinaGeorgescu Because I don't know how to use address MovieClips that are already instantiated on the stage, within classes. Commented Jul 1, 2014 at 20:39

1 Answer 1

1

there would be a lot to say about your code ! Your Array Main.Okchurray is most probably empty because you did not push anything to it (at least not in the code you published), so Main.Okchurray[0] is undefined, and undefined.x throws the TypeError: Error #1010. In other words you are trying to use a value that you have not initialized

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.