Possible to use Flex Framework/Components without using MXML?

后端 未结 4 1689
情话喂你
情话喂你 2020-12-08 10:56

Is it possible to use the Flex Framework and Components, without using MXML? I know ActionScript pretty decently, and don\'t feel like messing around with some new XML langu

4条回答
  •  独厮守ぢ
    2020-12-08 11:56

    I did a simple bootstrap similar to Borek (see below). I would love to get rid of the mxml file, but if I don't have it, I don't get any of the standard themes that come with Flex (haloclassic.swc, etc). Does anybody know how to do what Theo suggests and still have the standard themes applied?

    Here's my simplified bootstrapping method:

    main.mxml

    
    
    

    ApplicationClass.as

    package components {
        import mx.core.Application;
        import mx.events.FlexEvent;
        import flash.events.MouseEvent;
        import mx.controls.Alert;
        import mx.controls.Button;
    
        public class ApplicationClass extends Application {
            public function ApplicationClass () {
                addEventListener (FlexEvent.CREATION_COMPLETE, handleComplete);
            }
            private function handleComplete( event : FlexEvent ) : void {
                var button : Button = new Button();
                button.label = "My favorite button";
                button.styleName="halo"
                button.addEventListener(MouseEvent.CLICK, handleClick);
                addChild( button );
            }
            private function handleClick(e:MouseEvent):void {
                Alert.show("You clicked on the button!", "Clickity");
            }
        }
    }
    

    Here are the necessary updates to use it with Flex 4:

    main.mxml

    
    
    

    MyApplication.as

    package components {
        import flash.events.MouseEvent;
        import mx.controls.Alert;
        import mx.events.FlexEvent;
        import spark.components.Application;
        import spark.components.Button;
    
        public class MyApplication extends Application {
            public function MyApplication() {
                  addEventListener(FlexEvent.CREATION_COMPLETE, creationHandler);
            }
            private function creationHandler(e:FlexEvent):void {
                var button : Button = new Button();
                button.label = "My favorite button";
                button.styleName="halo"
                button.addEventListener(MouseEvent.CLICK, handleClick);
                addElement( button );
            }
            private function handleClick(e:MouseEvent):void {
                Alert.show("You clicked it!", "Clickity!");
            }
        }
    }
    

提交回复
热议问题