页面

2011年4月9日星期六

关于flex框架启动的一些事(1)

flex编译器在编译flex工程时会创建出四个基本类:

//
_MyProject_mx_managers_SystemManager  extends mx.managers.SystemManager
SystemManager类为flash项目的文档类
这里flex编译器会为项目生成一个SystemManager的子类,在其中生成与项目相关的一些数据,如:
  create()方法中定义该项目的主类名称;
  info()方法中生成很多与项目相关的信息

//
MyProject extends spark.components.Application

Application为项目的主类
这里flex编译器会为项目生成一个Application的子类,在该类要完成做为容器的功能(mxmlcontent),还要完成整个项目的style功能:
  在set moduleFactory(factory:IFlexModuleFactory)方法(被加入显示列表前调用)中调用一个生成的MyProject_StylesInit()方法,在该方法中完成自定义css文件中所有样式的注册,如:
        selector = null;
        conditions = null;
        conditions = [];
        condition = new CSSCondition("class", "Button1");
        conditions.push(condition);
        selector = new CSSSelector("spark.components.Button", conditions, selector);
        // spark.components.Button.Button1
        style = styleManager.getStyleDeclaration("spark.components.Button.Button1");
        if (!style)
        {
            style = new CSSStyleDeclaration(selector, styleManager);
        }

        if (style.factory == null)
        {
            style.factory = function():void
            {
                this.backgroundImage = _embed_css____assets_ui_add_png_867674143;
            };
        }
//
_TestProject_FlexInit
[Mixin]类,被写入SystemManager::info()["minxins"]中,在SystemManager初始货完成加载Application之前(SystemManager::kickoff()中)调用静态的init方法

此类完成各种单例、效果、别名等的注册

//
_TestProject_Styles
[Mixin]类,被写入SystemManager::info()["minxins"]中,在SystemManager初始货完成加载Application之前(SystemManager::kickoff()中)调用静态的init方法

此类完成系统内置组件样式、皮肤的绑定,如:

        selector = null;
        conditions = null;
        conditions = null;
        selector = new CSSSelector("spark.components.Button", conditions, selector);
        mergedStyle = styleManager.getMergedStyleDeclaration("spark.components.Button");
        style = new CSSStyleDeclaration(selector, styleManager, mergedStyle == null);

        if (style.defaultFactory == null)
        {
            style.defaultFactory = function():void
            {
                this.skinClass = spark.skins.spark.ButtonSkin;
            };
        }


        if (mergedStyle != null &&
            (mergedStyle.defaultFactory == null ||
            ObjectUtil.compare(new style.defaultFactory(), new mergedStyle.defaultFactory())))
        {
            styleManager.setStyleDeclaration(style.mx_internal::selectorString, style, false);
        }


///////////////////////////////////

根据这些信息,可以思考如何优化flex工程的编译速度,及缩减项目swf的大小

没有评论:

发表评论