0
votes

I am getting the following errors:

Scene 1, Layer 'Actions', Frame 1, Line 110, Column 14 1061: Call to a possibly undefined method addEventListener through a reference with static type Class.

Scene 1, Layer 'Actions', Frame 1, Line 113, Column 14 1061: Call to a possibly undefined method removeEventListener through a reference with static type Class.

Scene 1, Layer 'Actions', Frame 1, Line 128, Column 14 1061: Call to a possibly undefined method addEventListener through a reference with static type Class.

Scene 1, Layer 'Actions', Frame 1, Line 131, Column 14 1061: Call to a possibly undefined method removeEventListener through a reference with static type Class.

the code part is:

    function allowTapCaveman():void {
/*line 110*/    btn_caveman.addEventListener(TouchEvent.TOUCH_TAP, btn_cavemanMenu);
    }
    function cancelTapCaveman():void {
/*line 113*/    btn_caveman.removeEventListener(TouchEvent.TOUCH_TAP, btn_cavemanMenu);
    }
    function allowTapCavemanClose():void {
/*line 128*/    btn_caveman.addEventListener(TouchEvent.TOUCH_TAP, btn_cavemanMenuClose);
    }
    function cancelTapCavemanClose():void {
/*line 138*/    btn_caveman.removeEventListener(TouchEvent.TOUCH_TAP, btn_cavemanMenuClose);
    }

btn_caveman is a movieclip (yeah I know I have 'btn') that gets called on the stage via an array;

var startingcaveman:Array = new Array();
for (var i:Number = 0; i<2; i++) {
    startingcaveman.push(new btn_caveman());
    addChild(startingcaveman[i]);
    startingcaveman[i].name = 'startingcavemen' +i;
    startingcaveman[i].x = Math.random()*550;
    startingcaveman[i].y = Math.random()*400;
}
    startingcaveman[0].x = 213.60;
    startingcaveman[0].y = 312.90;
    startingcaveman[1].x = 211.75;
    startingcaveman[1].y = 400.15;
    stage.addEventListener(Event.ENTER_FRAME, example);
    function example (evt:Event) {
        for each (var btn_caveman in startingcaveman) {
            addEventListener(TouchEvent.TOUCH_TAP, btn_cavemanMenu3);
        }
    }

It's probably so simple but I can't get it which is annoying the hell outta me.

2
It means btn_caveman is the name of a class rather than an instance of a class.Marty
@Marty Sorry maybe its because I have spent too long doing it but what on earth do I do to make it work? Im doing this as a part of a group assessment for Uni and my group isnt helping me at all, all they are doing is playing games -.-Robdogga55
Either change the class name or the variable name to something different.Marty

2 Answers

1
votes

The simple answer which should allow you to fix your problem and in view of your coding style maybe get rid of many future problems as well:

You cannot use as a variable name the name of a class. In your case you have a class named btn_caveman but later on you try to use a variable named btn_caveman as well. Do not do that ever.

If you were to follow coding conventions you would never run into those type of problems. Class names should be that way:

ButtonCaveman

Variable name should be that way:

buttonCaveman
0
votes

This should to it

var startingcaveman:Array = [];
for (var i:Number = 0; i<2; i++) {
  // symbols should start with an upcase letter,
  // because they're classes
  // stick to "Caveman" for example
  var btn:MovieClip = new btn_caveman();
  startingcaveman.push(btn);
  addChild(btn);
  btn.name = 'startingcavemen' +i;
  btn.x = Math.random()*550;
  btn.y = Math.random()*400;
}

startingcaveman[0].x = 213.60;
startingcaveman[0].y = 312.90;
startingcaveman[1].x = 211.75;
startingcaveman[1].y = 400.15;
stage.addEventListener(Event.ENTER_FRAME, example);

function example (evt:Event) {
    // here was the error. you used the class name.
    // that's why naming is important!
    for each (var btn in startingcaveman) {
        btn.addEventListener(TouchEvent.TOUCH_TAP, btn_cavemanMenu3);
    }
}