我正在尝试从我孩子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 ("");
}
}
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("");}
}
现在你可以看到,我尝试了trace
方法,但没有运气。 Flash不会报告有关trace
方法的任何错误,但会报告两个未定义的变量(data_history
)。我试过在脚本顶部的所有函数上面使用trace方法,但仍然是相同的错误。
任何想法?
答案 0 :(得分:0)
儿童电影不应该以这种方式检查其父母。
试试这个:
在孩子的文件课程中:
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 ("");
}
}
答案 1 :(得分:0)
在跟踪中,您通过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("");}
}
如果您在那里的跟踪引发错误,则该属性从不存在于父级。