如何等到 adobe 动画 canvas 在 iframe 中绘制?

How to wait till adobe animation canvas drawn in iframe?

Adobe Animate Canvas 生成内容,我将该内容附加到 iframe 中。然后绘制canvas并在iframe文档中创建各种脚本变量。

我需要访问在完全加载 adobe 动画的 iframe 时生成的变量 'stage'。

我现在必须做的 - 附加 setTimeout 然后它似乎可以访问。 如果我不附加超时,控制台会抛出错误。

我想要实现的目标 - 我想以更好的方式避免 setTimeout 和重构代码。

我试过了jquery:

$element.on( 'load', function() {
    // Gives error when accessing the stage property
    $element[0].contentWindow.stage
    // allows to access stage property
    setTimeout(() => {
        console.log($element[0].contentWindow.stage)
    }, 1000)
});

所以基本上我已经尝试了很多建议。

尝试过:

$(element).load
$(element).on('load')
Other stuff...

对我有用的是这段代码:


    var onFullLoad = function(iframe) {
        return new Promise((resolve) => {
          var wait = function() {
            if (iframe && iframe.contentWindow && iframe.contentWindow.YourTargetedVariable) {
              resolve(iframe);
            } else {
              window.requestAnimationFrame(wait);
            }
          };
          wait();
        })
      };

那你可以这样继续:

onFullLoad(yourTargetIframe).then(function(){
//your code
});