可以使用Flex框架/组件,而不使用MXML? [英] Possible to use Flex Framework/Components without using MXML?

查看:166
本文介绍了可以使用Flex框架/组件,而不使用MXML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能使用Flex框架和组件,而不使用MXML?我知道动作pretty的体面,也不要觉得自己瞎搞了一些新的XML语言只是为了得到一些简单的用户界面在那里。任何人都可以提供包括可以被编译的。作为文件的例子(理想情况下通过FlashDevelop中,虽然只是讲了如何使用Flex SDK做到这一点是确定的也行),并使用Flex框架?例如,只是显示一个Flex按钮,弹出打开警报将是完美的。

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 language just to get some simple UI in there. Can anyone provide an example consisting of an .as file which can be compiled (ideally via FlashDevelop, though just telling how to do it with the Flex SDK is ok too) and uses the Flex Framework? For example, just showing a Flex button that pops open an Alert would be perfect.

如果这是不可能的,有人可以提供一个最小的MXML文件,该文件将引导一个自定义AS类,然后可以访问的Flex SDK?

If it's not possible, can someone provide a minimal MXML file which will bootstrap a custom AS class which then has access to the Flex SDK?

推荐答案

我做了类似博雷克(见下文)的简单引导。我很想摆脱MXML文件,但如果我没有,我没有得到任何的附带的Flex(haloclassic.swc等)的标准主题。是否有人知道如何做西奥表明,仍然有标准的主题应用?

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

main.mxml

<?xml version="1.0" encoding="utf-8"?>
<custom:ApplicationClass xmlns:custom="components.*"/>

ApplicationClass.as

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


下面是必要的更新,将其用于Flex 4的:


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

main.mxml

main.mxml

<?xml version="1.0" encoding="utf-8"?>
<local:MyApplication xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:local="components.*" />

MyApplication.as

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!");
        }
    }
}

这篇关于可以使用Flex框架/组件,而不使用MXML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆