将变量从父级传递给子级的问题。 AS3

发布于 2024-12-10 00:41:18 字数 1553 浏览 0 评论 0原文

我正在尝试从我的孩子 MC 中的父母那里访问一些变量。

父代码:

var data_history:String;    
function finish_checkUp(event:Event):void{          
        var checkUp_stat:String;
        checkUp_stat = data.check_UP_STAT;
        if (checkUp_stat == "PASSED"){
            data_history = "FALSE";
            gotoAndPlay ("domain_check");
        }
        else if (checkUp_stat == "FAILED"){
            data_history = "TRUE";
            gotoAndPlay ("error_data_conflict");
        }
        else if (checkUp_stat == "FAILED_UN"){
            data_history = "TRUE";
            gotoAndPlay ("");
        }   
}

子MC:

 contt_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseClick);
    contt_btn.addEventListener(MouseEvent.ROLL_OVER,contt_btnOver);
    contt_btn.addEventListener(MouseEvent.ROLL_OUT,contt_btnOut);
    function contt_btnOver(event:MouseEvent):void{
        contt_btn.gotoAndPlay("over");
    }
    function contt_btnOut(event:MouseEvent):void{
        contt_btn.gotoAndPlay("out");
    }
    function mouseClick(event:MouseEvent):void
    {
        trace (MovieClip(this.parent).data_history);
        if (data_history == "TRUE"){
    MovieClip(parent).gotoAndPlay("begin_erasing");
        }
        else if (data_history == "FALSE"){
            gotoAndPlay("");}
    }

现在正如你所看到的,我已经尝试了trace方法,但没有运气。 Flash 不会报告有关 trace 方法的任何错误,但会报告两个未定义的变量 (data_history)。我尝试在脚本顶部的所有函数之上使用跟踪方法,但仍然出现相同的错误。

有什么想法吗?

I'm trying to access some variables from my parent in my child MC.

Parent code:

var data_history:String;    
function finish_checkUp(event:Event):void{          
        var checkUp_stat:String;
        checkUp_stat = data.check_UP_STAT;
        if (checkUp_stat == "PASSED"){
            data_history = "FALSE";
            gotoAndPlay ("domain_check");
        }
        else if (checkUp_stat == "FAILED"){
            data_history = "TRUE";
            gotoAndPlay ("error_data_conflict");
        }
        else if (checkUp_stat == "FAILED_UN"){
            data_history = "TRUE";
            gotoAndPlay ("");
        }   
}

CHILD MC:

 contt_btn.addEventListener(MouseEvent.MOUSE_DOWN, mouseClick);
    contt_btn.addEventListener(MouseEvent.ROLL_OVER,contt_btnOver);
    contt_btn.addEventListener(MouseEvent.ROLL_OUT,contt_btnOut);
    function contt_btnOver(event:MouseEvent):void{
        contt_btn.gotoAndPlay("over");
    }
    function contt_btnOut(event:MouseEvent):void{
        contt_btn.gotoAndPlay("out");
    }
    function mouseClick(event:MouseEvent):void
    {
        trace (MovieClip(this.parent).data_history);
        if (data_history == "TRUE"){
    MovieClip(parent).gotoAndPlay("begin_erasing");
        }
        else if (data_history == "FALSE"){
            gotoAndPlay("");}
    }

Now as you can see, i have tried the trace method, but with no luck. Flash doesn't report any errors regarding the trace method, but does report the two undefined vars (data_history). Ive tried to use the trace method above all the functions, at the top of the script, still the same errors though.

any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

赴月观长安 2024-12-17 00:41:18

在跟踪中,您通过 this.parent 引用 data_history 属性。假设跟踪您的值,您需要调整您的 if...else 以通过父级引用该属性:

function mouseClick(event:MouseEvent):void
{
    trace (MovieClip(this.parent).data_history);
    if (MovieClip(this.parent).data_history == "TRUE"){
MovieClip(parent).gotoAndPlay("begin_erasing");
    }
    else if (MovieClip(this.parent).data_history == "FALSE"){
        gotoAndPlay("");}
}

如果您在那里的跟踪抛出错误,则该属性在父级上永远不存在。

In the trace, you are referencing the data_history property through this.parent. Assuming that traces your value, you need to adjust your if...else to reference the property through parent as well:

function mouseClick(event:MouseEvent):void
{
    trace (MovieClip(this.parent).data_history);
    if (MovieClip(this.parent).data_history == "TRUE"){
MovieClip(parent).gotoAndPlay("begin_erasing");
    }
    else if (MovieClip(this.parent).data_history == "FALSE"){
        gotoAndPlay("");}
}

If the trace you have in there throws an error, then the property never existed on parent.

╭ゆ眷念 2024-12-17 00:41:18

子电影不应该以这种方式检查其父电影。

试试这个:

在子文档中类:

public var data_history:String;
function mouseClick(event:MouseEvent):void{
           if (data_history == "TRUE"){
                  MovieClip(parent).gotoAndPlay("begin_erasing");
           }
           else if (data_history == "FALSE"){
                   gotoAndPlay("");}
           }
 }

在父文档中

function finish_checkUp(event:Event):void{ 
          var checkUp_stat:String;
          checkUp_stat = data.check_UP_STAT;
          if (checkUp_stat == "PASSED"){
              data_history = "FALSE";
              if (childMC as ChildDocumentClass) {
                  (childMC as ChildDocumentClass).data_history = data_history;
              }
              gotoAndPlay ("domain_check");
          }
          else if (checkUp_stat == "FAILED"){
              data_history = "TRUE";
              if (childMC as ChildDocumentClass) {
                  (childMC as ChildDocumentClass).data_history = data_history;
              }
              gotoAndPlay ("error_data_conflict");
          }
          else if (checkUp_stat == "FAILED_UN"){
              data_history = "TRUE";
              if (childMC as ChildDocumentClass) {
                  (childMC as ChildDocumentClass).data_history = data_history;
              }
              gotoAndPlay ("");
          }
  }  

The child movie should not be inspecting its parent in this way.

Try this:

in the child's document Class:

public var data_history:String;
function mouseClick(event:MouseEvent):void{
           if (data_history == "TRUE"){
                  MovieClip(parent).gotoAndPlay("begin_erasing");
           }
           else if (data_history == "FALSE"){
                   gotoAndPlay("");}
           }
 }

in the parent

function finish_checkUp(event:Event):void{ 
          var checkUp_stat:String;
          checkUp_stat = data.check_UP_STAT;
          if (checkUp_stat == "PASSED"){
              data_history = "FALSE";
              if (childMC as ChildDocumentClass) {
                  (childMC as ChildDocumentClass).data_history = data_history;
              }
              gotoAndPlay ("domain_check");
          }
          else if (checkUp_stat == "FAILED"){
              data_history = "TRUE";
              if (childMC as ChildDocumentClass) {
                  (childMC as ChildDocumentClass).data_history = data_history;
              }
              gotoAndPlay ("error_data_conflict");
          }
          else if (checkUp_stat == "FAILED_UN"){
              data_history = "TRUE";
              if (childMC as ChildDocumentClass) {
                  (childMC as ChildDocumentClass).data_history = data_history;
              }
              gotoAndPlay ("");
          }
  }  
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文