我需要在actionscript 3中更改父级中的变量

时间:2010-03-06 18:10:57

标签: flash actionscript-3 variables parent-child

我是动作脚本3的新手。我想在单击子项中的按钮时将父项中的变量设置更改为1。

这是父级零.wf:

var noPass:Number=0;

function getPass(event:onLoad, noPass):void {
    if(noPass==0) {
        var passRequest:URLRequest=new URLRequest("PasswordPage.swf");
        var passLoader:Loader = new Loader();
        passLoader.load(passRequest);
        addChild(passLoader);
    } else {
        removeChild(passLoader);
        var navRequest:URLRequest=new URLRequest("nav/ILNav.swf");
        var navLoader:Loader = new Loader();
        navLoader.load(navRequest);
        addChild(navLoader);
    }
}

addEventListener(onLoad, getPass, noPass)

这是孩子PasswordPage.swf:

submit_btn.addEventListener(MouseEvent.CLICK, subClick, noPass);

var myName:String;
var myPass:String;

function subClick(event:MouseEvent, noPass):void {

    myName=name_txt.text;
    myPass=pass_txt.text;
    failedName_txt.text="";
    failedPass_txt.text="";

    if (myName=="Kim"&&myPass=="Pablo") {
        //this.parent.removeChild(this);
        //DisplayObjectContainer(this.parent).removeChild(this);
        //unload(passLoader);
        noPass=1


    } else if (myName != "Kim") {
        failedName_txt.text="You have entered the wrong Username.";
    } else {
        failedPass_txt.text="You have entered the wrong Password.";
    }
}

1 个答案:

答案 0 :(得分:0)

您始终可以从父swf中将鼠标事件侦听器添加到子项的按钮中。例如,在父剪辑中,您可以执行以下操作:

var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, _configureChild, false, 0, true);
loader.load(new URLRequest("PasswordPage.swf"));

function _configureChild(e:Event):void {
   var info:LoaderInfo = e.target as LoaderInfo;
   var mov:MovieClip = info.loader.content as MovieClip;
   var btn:MovieClip = mov.getChildByName("submit_btn") as MovieClip; 
   submit_btn.addEventListener(MouseEvent.CLICK, _childClickHandle, false, 0, true);

}

function _childClickHandle(e:MouseEvent):void {
   /// blah blah blah
}