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

Dynamic path

Community Beginner ,
Dec 17, 2017 Dec 17, 2017

Hi, I have functions i have to re-use with differents objects, i don't want to write a function for each symbol as they use the same mecanisms, but i don't know how to use dynamic targeting and parameters, everything i tried did'nt worked

for example, i tried to pass the instance name in parameters of the function, it does not work :

this.auto.addEventListener("click", obj_function.bind(this, obj='auto'));

function obj_function.(obj) {

    this.obj.goToAndStop(); 

    this.obj.removeEventListener();

}

Thanks for your help

135
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

correct answers 1 Correct answer

LEGEND , Dec 17, 2017 Dec 17, 2017

I hadn't thought about working that way before, and I'll check into whether it works like I think it would.

Assuming it works, either of these might do better:

this.auto.addEventListener("click", obj_function.bind(this, obj='auto'));

function obj_function.(obj) {

    this[obj].goToAndStop();

    this[obj].removeEventListener("click",obj_function);

}

or:

this.auto.addEventListener("click", obj_function.bind(obj=this.auto));

function obj_function.(obj) {

    obj.goToAndStop();

    obj.removeEventListener("

...
Translate
LEGEND ,
Dec 17, 2017 Dec 17, 2017

I hadn't thought about working that way before, and I'll check into whether it works like I think it would.

Assuming it works, either of these might do better:

this.auto.addEventListener("click", obj_function.bind(this, obj='auto'));

function obj_function.(obj) {

    this[obj].goToAndStop();

    this[obj].removeEventListener("click",obj_function);

}

or:

this.auto.addEventListener("click", obj_function.bind(obj=this.auto));

function obj_function.(obj) {

    obj.goToAndStop();

    obj.removeEventListener("click",obj_function);

}

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 Beginner ,
Dec 17, 2017 Dec 17, 2017
LATEST

Thanks a lot, it works perfectly (  I tried the first solution).

Best Regards

Gilles

this[obj]

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