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

Call EventListener witch is in another function

Explorer ,
Dec 10, 2020 Dec 10, 2020

Copy link to clipboard

Copied

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

Views

378

Translate

Translate

Report

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

Copy link to clipboard

Copied

Hi.

 

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

 

Is it possible?

 

Regards,

JC

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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 

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

 

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

What kind of interactivity do you want to achieve?

 

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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();

 

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

In this case How I can call function B ?

 

if I call B();

1180: Call to a possibly undefined method B.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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