开发者

how to use this as class code in mmxl aaplication?

I have taken this code from one of my friend,but in real it is totally mess there are plenty of error i am getting by running this code,i have some question

  1. How i can use this code in mxml application,as we know we can not use public class in mx script so what are the way to do that
  2. as you can see .mx_internal,i am getting error on that saying'define object before dot' as i remove mx_internal and tried using import mx.binding.mx_internal and use namespace mx_internal application not desplaying anything

now you will tell me ther are easy methods are ther to solve problem but my whole project is on this method only

thanks for help in advance i am trying to solve this problem from last 15 days ,with no success,pls help me below is code

package components
{
    import flash.events.*;
    import flash.utils.*;
    import mx.binding.*;
    import mx.containers.*;
    import mx.controls.*;
    import mx.core.*;
    import mx.events.*;
    import mx.styles.*;

    public class DialogTitle extends HBox implements IBindingClient
    {
        private var _110371416title:String = "Dialog Title";
        public var _DialogTitle_Image1:Image;
        public var _DialogTitle_Image2:Image;
        public var _DialogTitle_Label1:Label;
        var _bindingsBeginWithWord:Object;
        private var _1859425293showCloseButton:Boolean = false;
        var _bindingsByDestination:Object;
        var _watchers:Array;
        var _bindings:Array;
        private var _documentDescriptor_:UIComponentDescriptor;
        private static var _watcherSetupUtil:IWatcherSetupUtil;

        public function DialogTitle()
        {
            _documentDescriptor_ = new UIComponentDescriptor({type:HBox, propertiesFactory:function () : Object
            {
                return {height:27, childDescriptors:[new UIComponentDescriptor({type:Spacer, propertiesFactory:function () : Object
                {
                    return {width:5};
                }// end function
                }), new UIComponentDescriptor({type:Image, id:"_DialogTitle_Image1"}), new UIComponentDescriptor({type:Spacer, propertiesFactory:function () : Object
                {
                    return {width:5};
                }// end function
                }), new UIComponentDescriptor({type:Label, id:"_DialogTitle_Label1", stylesFactory:function () : void
                {
                    this.fontSize = 14;
                    this.color = 16777215;
                    this.fontWeight = "bold";
                    return;
                }// end function
                }), new UIComponentDescriptor({type:Spacer, propertiesFactory:function () : Object
                {
                    return {percentWidth:100};
                }// end function
                }), new UIComponentDescriptor({type:Image, id:"_DialogTitle_Image2", events:{click:"___DialogTitle_Image2_click"}, propertiesFactory:function () : Object
                {
                    return {useHandCursor:true, buttonMode:true, mouseChildren:false, toolTip:"Close"};
                }// end function
                }), new UIComponentDescriptor({type:Spacer, propertiesFactory:function () : Object
                {
                    return {width:13};
                }// end function
                })]};
            }// end function
            });
            _bindings = [];
            _watchers = [];
            _bindingsByDestination = {};
            _bindingsBeginWithWord = {};
            mx_internal::_document = this;
            if (!this.styleDeclaration)
            {
                this.styleDeclaration = new CSSStyleDeclaration();
            }
            this.styleDeclaration.defaultFactory = function () : void
            {
                this.backgroundColor = 9947478;
                this.horizontalGap = 0;
                this.verticalAlign = "middle";
                this.verticalGap = 0;
                return;
            }// end function
            ;
            this.height = 27;
            this.percentWidth = 100;
            return;
        }// end function

        private function _DialogTitle_bindingExprs() : void
        {
            var _loc_1:* = undefined;
            _loc_1 = CustomEmbeddedAssets.logoImageSmall;
            _loc_1 = title;
            _loc_1 = EmbeddedAssets.dialogClose;
            _loc_1 = showCloseButton;
            return;
        }// end function

        public function get showCloseButton() : Boolean
        {
            return this._1859425293showCloseButton;
        }// end function

        override public function initialize() : void
        {
            var target:DialogTitle;
            var watcherSetupUtilClass:Object;
            .mx_internal::setDocumentDescriptor(_documentDescriptor_);
            var bindings:* = _DialogTitle_bindingsSetup();
            var watchers:Array;
            target;
            if (_watcherSetupUtil == null)
            {
                watcherSetupUtilClass = getDefinitionByName("_components_DialogTitleWatcherSetupUtil");
                var _loc_2:* = watcherSetupUtilClass;
                _loc_2.watcherSetupUtilClass["init"](null);
            }
            _watcherSetupUtil.setup(this, function (param1:String)
            {
                return target[param1];
            }// end function
            , bindings, watchers);
            var i:uint;
            while (i < bindings.length)
            {

                Binding(bindings[i]).execute();
                i = (i + 1);
            }
            mx_internal::_bindings = mx_internal::_bindings.concat(bindings);
            mx_internal::_watchers = mx_internal::_watchers.concat(watchers);
            super.initialize();
            return;
        }// end function

        public function get title() : String
        {
            return this._110371416title;
        }// end function

        private function _DialogTitle_bindingsSetup() : Array
        {
            var binding:Binding;
            var result:Array;
            binding = new Binding(this, function () : Object
            {
                return CustomEmbeddedAssets.logoImageSmall;
            }// end function
            , function (param1:Object) : void
            {
                _DialogTitle_Image1.source = param1;
                return;
            }// end function
            , "_DialogTitle_Image1.source");
            result[0] = binding;
            binding = new Binding(this, function () : String
            {
                var _loc_1:* = title;
                var _loc_2:* = _loc_1 == undefined ? (null) : (String(_loc_1));
                return _loc_2;
            }// end function
            , function (param1:String) : void
            {
                _DialogTitle_Label1.text = param1;
                return;
            }// end function
            , "_DialogTitle_Label1.text");
            result[1] = binding;
            binding = new Binding(this, function () : Object
            {
                return EmbeddedAssets.dialogClose;
            }// e开发者_StackOverflow中文版nd function
            , function (param1:Object) : void
            {
                _DialogTitle_Image2.source = param1;
                return;
            }// end function
            , "_DialogTitle_Image2.source");
            result[2] = binding;
            binding = new Binding(this, function () : Boolean
            {
                return showCloseButton;
            }// end function
            , function (param1:Boolean) : void
            {
                _DialogTitle_Image2.visible = param1;
                return;
            }// end function
            , "_DialogTitle_Image2.visible");
            result[3] = binding;
            return result;
        }// end function

        public function set showCloseButton(param1:Boolean) : void
        {
            var _loc_2:* = this._1859425293showCloseButton;
            if (_loc_2 !== param1)
            {
                this._1859425293showCloseButton = param1;
                this.dispatchEvent(PropertyChangeEvent.createUpdateEvent(this, "showCloseButton", _loc_2, param1));
            }
            return;
        }// end function

        public function ___DialogTitle_Image2_click(event:MouseEvent) : void
        {
            dispatchEvent(new Event("onCancel"));
            parent.visible = false;
            return;
        }// end function

        public function set title(param1:String) : void
        {
            var _loc_2:* = this._110371416title;
            if (_loc_2 !== param1)
            {
                this._110371416title = param1;
                this.dispatchEvent(PropertyChangeEvent.createUpdateEvent(this, "title", _loc_2, param1));
            }
            return;
        }// end function

        public static function set watcherSetupUtil(param1:IWatcherSetupUtil) : void
        {
            DialogTitle._watcherSetupUtil = param1;
            return;
        }// end function

    }
}


Just throw this code out. This code was generated automatically by mxmlc compiler from MXML class and can't be used in production. It is for computer, not for humans. Write the right code by yourself. I hope it will be clearer and maintainable. And yes, this code wasn't written by your friend :)


This file is decompiled from a .mxml file, which use tags to describe layout. However, some decompiler can't convert it completely, and you will see file like this.

As you see, the argument of UIComponentDescriptor is an object, which contains a lot of key-val pairs. It has some type of keys:

  1. type:Class --> this is the type of this component, which is the node tag of .mxml file
  2. id:String --> this is the ID of a node, which is also the variable name you can use in <fx:Script> tag
  3. event:Object --> events that the component will trigger
  4. stylesFactory:Function --> component's styles setting
  5. propertiesFactory:Function --> contains some properties and child nodes

code like this:

<mx:Canvas id="mainCanvas" borderStyle="none" label="main">
  <mx:Button click="onClick(event)" />
</mx:Canvas>

will be converted into:

new UIComponentDescriptor({
    "type":Canvas,
    "id":mainCanvas,
    "styleFactory":function():void {
        this.borderStyle="none";
    },
    "propertiesFactory":function():Object {
        return({
            "label":"main"
            "childDescriptors":[new UIComponentDescriptor({
             // button's code in here
            });
            ]
        })
    }
})

For those events:

As you can write click event in mxml tags both like btnOnClick() and btnOnClick(event), the compiler need to do something to ensure the event handler accept a right argument. So, for the Button tag I just mention, the value corresponding to key"event" will be like this: {"click":"__on_click"}. Then the compiler will create a new function call __on_click, which may like this:

public function __on_click(event:MouseEvent):void {
    onClick(event);
}

Obviously, after you convert the UIComponentDescriptor into .mxml, you should replace the events function.

For the constructor:

.mxml file can not has a constructor, but the compiler will create one in .as file, which contains the UIComponentDescriptor. The constructor will also do some initialization for it's variables. When converting to .mxml file, you need to do this initialization after the variable's declaration. For example:

public function MyCanvas(){
    this._documentDescriptor_ = new UIComponentDescriptor({
    //……
    });
    this.myArray = new Array();
}

you should convert it into this:

<fx:Script><![CDATA[
var myArray:Array = new Array();
]]></fx:Script>

So the heaviest work is to convert UIComponentDescriptor into .mxml tags. And here is a simple python script that can help you do it:

UIComponentDescriptor2XML

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜