从外部类更改主类的变量

时间:2012-12-13 20:53:40

标签: actionscript-3 class variables public-method

我想通过外部类video01中的函数terug在我的Main.as中将var filmAan更改为false。

这是我的Main.as

package 
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
import fl.video.*;

public class Main extends MovieClip 
{
    public function Main() 
    {
        trace( "hij werkt" ); 

        btn_1.addEventListener(MouseEvent.CLICK,speel1);
        btn_2.addEventListener(MouseEvent.CLICK,speel2);
        btn_3.addEventListener(MouseEvent.CLICK,speel3);
        btn_4.addEventListener(MouseEvent.CLICK,speel4);
        btn_5.addEventListener(MouseEvent.CLICK,speel5);
        btn_6.addEventListener(MouseEvent.CLICK,speel6);
        btn_7.addEventListener(MouseEvent.CLICK,speel7);
        btn_8.addEventListener(MouseEvent.CLICK,speel8);
        btn_9.addEventListener(MouseEvent.CLICK,speel9);

        var mc_video01:MovieClip = new video01();
        var mc_video02:MovieClip = new video02();
        var mc_video03:MovieClip = new video03();
        var mc_video04:MovieClip = new video04();
        var mc_video05:MovieClip = new video05();
        var mc_video06:MovieClip = new video06();
        var mc_video07:MovieClip = new video07();
        var mc_video08:MovieClip = new video08();
        var mc_video09:MovieClip = new video09();

        public var filmAan = false;

        function speel1(evtObj:MouseEvent):void 
        {
            if (filmAan == false) 
            {
                trace("knop 1 werkt");              

                addChild(mc_video01);
                mc_video01.x=340; 
                mc_video01.y=227;
                mc_video01.width=1360;
                mc_video01.height=1060;

                filmAan = true;
            }
            else
            {
                trace("knop 1 uitgeschakeld");
            }
        }

        function speel2(evtObj:MouseEvent):void 
        {
            if (filmAan == false) 
            {               
                trace("knop 2 werkt");

                addChild(mc_video02);
                mc_video02.x=340; 
                mc_video02.y=227;
                mc_video02.width=1360;
                mc_video02.height=1060;

                filmAan = true;
            }
            else
            {
                trace("knop 2 uitgeschakeld");
            }
        }

        function speel3(evtObj:MouseEvent):void 
        {           
            if (filmAan == false) 
            {
                trace("knop 3 werkt");

                addChild(mc_video03);
                mc_video03.x=340; 
                mc_video03.y=227;
                mc_video03.width=1360;
                mc_video03.height=1060;

                filmAan = true;
            }
            else
            {
                trace("knop 3 uitgeschakeld");
            }
        }

        function speel4(evtObj:MouseEvent):void 
        {
            if (filmAan == false) 
            {
                trace("knop 4 werkt");

                addChild(mc_video04);
                mc_video04.x=340; 
                mc_video04.y=227;
                mc_video04.width=1360;
                mc_video04.height=1060;

                filmAan = true;
            }
            else
            {
                trace("knop 4 uitgeschakeld");
            }
        }

        function speel5(evtObj:MouseEvent):void 
        {
            if (filmAan == false) 
            {
                trace("knop 5 werkt");

                addChild(mc_video05);
                mc_video05.x=340; 
                mc_video05.y=227;
                mc_video05.width=1360;
                mc_video05.height=1060;

                filmAan = true;
            }
            else
            {
                trace("knop 5 uitgeschakeld");
            }
        }

        function speel6(evtObj:MouseEvent):void 
        {
            if (filmAan == false) 
            {
                trace("knop 6 werkt");

                addChild(mc_video06);
                mc_video06.x=340; 
                mc_video06.y=227;
                mc_video06.width=1360;
                mc_video06.height=1060;

                filmAan = true;
            }
            else
            {
                trace("knop 6 uitgeschakeld");
            }
        }

        function speel7(evtObj:MouseEvent):void 
        {
            if (filmAan == false) 
            {
                trace("knop 7 werkt");

                addChild(mc_video07);
                mc_video07.x=340; 
                mc_video07.y=227;
                mc_video07.width=1360;
                mc_video07.height=1060;

                filmAan = true;
            }
            else
            {
                trace("knop 7 uitgeschakeld");
            }
        }

        function speel8(evtObj:MouseEvent):void 
        {
            if (filmAan == false) 
            {
                trace("knop 8 werkt");

                addChild(mc_video08);
                mc_video08.x=340; 
                mc_video08.y=227;
                mc_video08.width=1360;
                mc_video08.height=1060;

                filmAan = true;
            }
            else
            {
                trace("knop 8 uitgeschakeld");
            }
        }

        function speel9(evtObj:MouseEvent):void 
        {
            if (filmAan == false) 
            {
                trace("knop 9 werkt");

                addChild(mc_video09);
                mc_video09.x=340; 
                mc_video09.y=227;
                mc_video09.width=1360;
                mc_video09.height=1060;

                filmAan = true;
            }
            else
            {
                trace("knop 9 uitgeschakeld");
            }
        }
    }
}   
}

这是我的video01.as

package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;

public class video01 extends MovieClip
{
    public function video01()
    {
        trace("movieclip 1 geladen");
        btn_terug.addEventListener(MouseEvent.CLICK, terug);
    }

    public function terug(evt:MouseEvent):void 
    {
        trace("knop ingedrukt");
        this.parent.removeChild(this);  

    }
}
}

我究竟如何从video01类更改Main.as中的var ??

提前谢谢!

1 个答案:

答案 0 :(得分:0)

看起来您的video01班级是Main班级的孩子。因此,您可以使用parent关键字来访问Main类。您需要强制转换父级以便不抛出编译器错误:

来自你的video01课程:

 Main(parent).filmAan = false;