Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Call EventListener witch is in another function

Explorer ,
Dec 10, 2020 Dec 10, 2020

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.

 

TOPICS
ActionScript
588
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 10, 2020 Dec 10, 2020

Hi.

 

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

 

Is it possible?

 

Regards,

JC

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 10, 2020 Dec 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 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 10, 2020 Dec 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.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 10, 2020 Dec 10, 2020

What kind of interactivity do you want to achieve?

 

Because I can hardly think of a situation that would require so much duplicate code.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 10, 2020 Dec 10, 2020

Event listeners add some keyboard functions, and its goes like this

when ends something do something

when again do something

 add some movie clips

and add event listener if some of them exists, if not add event listener for keyboard, if exists add event listenerss ENTER FRAME

when call some functions

and again when function ends add veent listener.

 

I just want to call ONE function from outside thats all I want

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 17, 2020 Dec 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();

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 19, 2020 Dec 19, 2020

In this case How I can call function B ?

 

if I call B();

1180: Call to a possibly undefined method B.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 19, 2020 Dec 19, 2020
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines