我需要在 ActionScript 3 中从子级更改父级中的变量

发布于 2024-08-24 06:55:24 字数 1405 浏览 9 评论 0原文

我是 actionscript 3 的新手。当单击子级中的按钮时,我想将父级中设置为 0 的变量更改为 1。

这是父零.swf:

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.";
    }
}

I am new at actionscript 3. I want to change a variable set to 0 in the parent to 1 when a button in the child is clicked.

This is the parent zero.swf:

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)

this is the child 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.";
    }
}

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

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

发布评论

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

评论(1

清风挽心 2024-08-31 06:55:24

您始终可以从父 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
}

You could always add your mouse event listeners to the child's button from within the parent swf. For example, in the parent clip you could do something like this:

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
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文