开发者

Flash AS3 Call of multiple properties for object in class

I have a MainClass and a GUIClass. The MainClass lets the GUIClass handle everything about the GUI. How do I call different Object properties from the MainClass to the GUIClass.

package {

    import gui;
    public class main {
        public var ui:Object = userInterface_mc as Object;
        public var myGui:gui = new gui;

        function main() {
                myGui.prepareObject(ui);
                myGui.tf01 = "foo";
        }
    }

package {
    public class gui {
        private var ui:Object;
        private var textField01:TextField = textField_01 as Textfield;

   开发者_开发技巧     function prepareObject (myUI:Object) {
                ui = myUI;
        }
        function set tf01 (myString:String) {
                textField01.text = myString;
        }
    }
}

The code shows how I pass the text property of a TextField. But now I have a ComboBox and I need to fill in data, clear it, receive the label and data. Is there any way to call it like

myData = GUI.comboBox01.data;
myLabel = GUI.comboBox01.label;
GUI.comboBox01.resetAll();
GUI.comboBox01.addItem({label:"foo", data:"baa"});

Best regards

TD


  1. Stick to naming conventions: Class names should start with an upper case letter, member names should start with a lower case letter.

  2. You can access any property within your gui object, if it is declared public. So if you make comboBox01 a public variable, it will be accessible.

Here's your new code - but not knowing what you're going to do with it, I can only assume where to put what:

package {

    import GUI;
    public class Main {
        public var ui:Object = userInterface_mc as Object;
        public var myGui:GUI = new GUI();
        private var myData : String;
        private var myLabel : String;
        public function main() {
            myGui.prepareObject(ui);
            myGui.tf01 = "foo";
            myData = myGUI.comboBox01.data;
            myLabel = myGUI.comboBox01.label;
            myGUI.comboBox01.resetAll();
            myGUI.comboBox01.addItem({label:"foo", data:"baa"});
        }
    }

package {
    public class GUI {
        private var ui:Object;
        private var textField01:TextField = textField_01 as Textfield;
        public var comboBox01:ComboBox;

        public function prepareObject (myUI:Object) {
                ui = myUI;
        }
        public function set tf01 (myString:String) {
                textField01.text = myString;
        }
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜