Skip to main content
dalvydasv27776233
Inspiring
December 10, 2020
Question

Call EventListener witch is in another function

  • December 10, 2020
  • 2 replies
  • 668 views

Hello, I have question and asking for help.

My script:

 

function A(){

    // doooo somthing...

    stage.addEventListener(Event.ENTER_FRAME, B);;

        function B(event: Event): void {

               // do something

         }

}

 

function C(){

stage.addEventListener(Event.ENTER _ FRAME, B);

}

 

ERROR:  1120: Access of undefined property B.

 

This topic has been closed for replies.

2 replies

AdrianaCampolina
Participating Frequently
December 17, 2020

I don't know if I understand it, but apparently the "C" function must execute the "B" function, so for that, you could create one more function, maybe it will solve:

 

// Test Example:

function A() {

trace("A");
// doooo somthing...

function D() {
trace("D - doooo somthing...");
stage.addEventListener(Event.ENTER_FRAME, B);
function B(event: Event): void {
trace("do something");
}
}
D();
}

function C() {
trace("C");
A();
}

C();

 

dalvydasv27776233
Inspiring
December 19, 2020

In this case How I can call function B ?

 

if I call B();

1180: Call to a possibly undefined method B.

dalvydasv27776233
Inspiring
December 19, 2020

function A(){
//do something
}

 

function B(){
//do something
}

 

function C(){
//do something
}

 

function D(){
//do something
}

 

In this case I can call A(), B(), C(), D() then ever I want and it works.

 

 

function A(){
//do something
function B(){
//do something
}
}


function C(){
//do something
}

function D(){
//do something
}

 

In this case dunction B is inside the function A. So if I call B();

1180: Call to a possibly undefined method B.

JoãoCésar17023019
Community Expert
Community Expert
December 10, 2020

Hi.

 

The easiest way for you will be to define the function B outside function A.

 

Is it possible?

 

Regards,

JC

dalvydasv27776233
Inspiring
December 10, 2020

Its posible but then I have to define others 9 functions and do changes in theese...  But I want to call for that EventListener and thats all job done. I want to know how I can do that 

dalvydasv27776233
Inspiring
December 10, 2020

I want to have one function ant that funcion does almost most job, And others just helping in some situations. Thats why I have functions inside function and now im in situation what I dont want same functions copy paste for doing the same job.