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

Object not yet loaded while running the function

New Here ,
Dec 04, 2017 Dec 04, 2017

In one of the frame, I have the following JS code to change the head.

However, the 'resultcharc' is 'undefined', I guess at the time it runs the code, the object is still not yet loaded.

I tried these methods, all failed.esultcharcto resultc

1. setTimeout(changeHead, 5000);

2. setInterval(changeHead, 5000);

3. document.addEventListener('DOMContentLoaded',changeHead.bind(this));

l.resultcharcresult

ult.resultcreeuelet.resultc

function changeHead() {

switch (parent.p1.classes){

case "basic":

this.start_result.resultcharb.gotoAndStop(parent.p1.head);

console.log("go to resultcharb");

break;

case "middle":

this.start_result.resultcharc.gotoAndStop(parent.p1.head);

console.log("go to resultcharc");

break;

}

}

changeHead();

But if I use click mehtod to trigger it, it works.

this.start_result.addEventListener('click', changeHead.bind(this));

function changeHead() {

  

switch (parent.p1.classes){

case "basic":

this.start_result.resultcharb.gotoAndStop(parent.p1.head);

console.log("go to resultcharb");

break;

case "middle":

this.start_result.resultcharc.gotoAndStop(parent.p1.head);

console.log("go to resultcharc");

break;

}

}

How can I fix it, so when the frame is loaded, the changeHead function can successfully run?

235
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

Community Expert , Dec 05, 2017 Dec 05, 2017

you have to wait until those frame labell loads to call changeHead.  (and you have to pass a reference to this.)

Translate
Community Expert ,
Dec 05, 2017 Dec 05, 2017
LATEST

you have to wait until those frame labell loads to call changeHead.  (and you have to pass a reference to this.)

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