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

Best way to call function from more than 1 event listener and pass parameter?

Explorer ,
Feb 08, 2018 Feb 08, 2018

I have a button bank that allows a quick search of a video component instance named "video0".  Rather than have a diff. function for each button, can I use one function and just pass to it the location I wish to seek to?  I tried this, but no luck...

_root.b1.addEventListener("click", govideo.bind(this,0));

_root.b2.addEventListener("click", govideo.bind(this,100));

_root.b3.addEventListener("click", govideo.bind(this,200));

function govideo(thetime) {

   _root.gotoAndPlay("video");

   video0.currentTime = thetime;

   $("#video0")[0].play();

}

178
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

Explorer , Feb 08, 2018 Feb 08, 2018

Oops!  My bad...  The code below is correct.  The problem was my video placeholder was not long enough for the time values I had specified.  Thanks

_root.b1.addEventListener("click", govideo.bind(this,0));

_root.b2.addEventListener("click", govideo.bind(this,100));

_root.b3.addEventListener("click", govideo.bind(this,200));

function govideo(thetime) {

   _root.gotoAndPlay("video");

   video0.currentTime = thetime;

   $("#video0")[0].play();

}

Translate
LEGEND ,
Feb 08, 2018 Feb 08, 2018

The code you showed seems to work exactly like you have it. At least as far as this line:

function govideo(thetime) {

There may be something going wrong after that. Where is video0 created? If it's a component you may need to do a getElementById() to get the video's reference.

Also, is the frame "video" somewhere that those three buttons don't exist? If they're not present you could add some removeEventListeners before going to the "video" frame:

function govideo(thetime) {

_root.b1.removeEventListener("click", govideo);

_root.b2.removeEventListener("click", govideo);

_root.b3.removeEventListener("click", govideo);

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 ,
Feb 08, 2018 Feb 08, 2018
LATEST

Oops!  My bad...  The code below is correct.  The problem was my video placeholder was not long enough for the time values I had specified.  Thanks

_root.b1.addEventListener("click", govideo.bind(this,0));

_root.b2.addEventListener("click", govideo.bind(this,100));

_root.b3.addEventListener("click", govideo.bind(this,200));

function govideo(thetime) {

   _root.gotoAndPlay("video");

   video0.currentTime = thetime;

   $("#video0")[0].play();

}

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