且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在子窗口中使用主窗口中的数据?

更新时间:2023-09-18 23:41:04

您可以向窗口类添加属性,并从应用程序传递数据.

You could add an attribute to your window class, and pass the data from the application.

有一个属性和一个setter函数:

With an attribute and a setter function :

myWindow.mxml:

myWindow.mxml :

    <![CDATA[
        private var _data : Array;

        public function set data(data : Array) : void {
             this._data = data;
        }

    ]]>

主要

    <![CDATA[
        public function openWin():void {
            var w : myWindow = new myWindow();
            w.data = myData;
            w.open();
        }

        public var myData:Array = new Array('The Eiffel Tower',
                                            'Paris','John Doe');
    ]]>

您也可以通过向窗口添加构造函数参数来实现,但您必须在 ActionScript 中编写 Window 组件.

You could also do it by adding a constructor parameter to your window, but you will have to write your Window component in ActionScript.

(另外:您可能希望使用 MyWindow 而不是 myWindow 作为组件的名称,但这只是传统的挑剔).

(Also : you might want to use MyWindow for the name of your component instead of myWindow, but that's just conventionnal nitpicking).

另外,注意有一个单例变量 Application.application 可以被 Application 中的所有类访问;但是我不知道这是否适用于 WindowedApplication,无论哪种方式,它都不是推荐的方法.

Also, note that there is a singleton variable Application.application that is accessible to all classes in an Application ; however I don't know if this applies to a WindowedApplication, and either way it is not the recommended approach.