将变量从父级传递给子级的问题。 AS3
我正在尝试从我的孩子 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在跟踪中,您通过
this.parent
引用 data_history 属性。假设跟踪您的值,您需要调整您的 if...else 以通过父级引用该属性:如果您在那里的跟踪抛出错误,则该属性在父级上永远不存在。
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:If the trace you have in there throws an error, then the property never existed on parent.
子电影不应该以这种方式检查其父电影。
试试这个:
在子文档中类:
在父文档中
The child movie should not be inspecting its parent in this way.
Try this:
in the child's document Class:
in the parent