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开发者_如何学JAVA the functions, at the top of the script, still the same errors though.
any ideas?
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.
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 ("");
}
}
精彩评论