2011-05-09 31 views
0

我採取了從我的一個朋友這樣的代碼,但在實際它是完全混亂有很多的錯誤,我感到運行此代碼獲得的,我有一些問題如何在mmxl中使用此類作爲類的代碼?

  1. 我如何在使用此代碼mxml應用程序,因爲我們知道我們不能在mx腳本中使用公共類,所以有什麼辦法做到這一點
  2. 正如你可以看到.mx_internal,我得到錯誤說'定義對象之前點'因爲我刪除mx_internal並嘗試使用導入mx.binding.mx_internal並使用命名空間mx_internal應用程序不會去掉任何東西

現在你會告訴我,它是簡單的方法是解決問題,但我的整個項目只有這種方法

感謝您的幫助提前 我想解決這個問題,從過去15天,沒有成功,請幫助我下面是代碼

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; 
      }// end 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 

    } 
} 

回答

1

只是拋出此代碼。此代碼是由MXML類的mxmlc編譯器自動生成的,不能用於生產。它用於計算機,不適用於人類。自己寫出正確的代碼。我希望它會更清晰和可維護。是的,這段代碼不是你的朋友寫的:)

+0

可能你是對的哥們但你可以給我的任何解決方案,如果運行至少我能知道什麼是錯誤等等我可以通過這種方式學習 – 2011-05-09 09:54:37

+0

只要MXML生成的代碼只是將MXML用於「DialogTitle」組件,或者讓您的朋友給您提供原始MXML版本的「DialogTitle」。 – Constantiner 2011-05-09 09:57:17

0

這個文件是從.mxml文件反編譯的,它使用標籤來描述佈局。但是,有些反編譯器不能完全轉換它,你會看到這樣的文件。

如您所見,UIComponentDescriptor的參數是一個對象,其中包含大量的鍵值對。它有一些類型的鍵:

  1. type:類 - >這是該組件,這是的.mxml文件的節點標籤的類型
  2. id:字符串 - >這是的ID一個節點,這也是變量名就可以在<fx:Script>標籤使用
  3. event:對象 - >事件組件將觸發
  4. stylesFactory:功能 - >組件的樣式設置
  5. propertiesFactory:FUNC重刑 - >包含一些屬性和子節點

這樣的代碼:

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

將被轉換成:

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

對於這些事件:

,你可以在mxml標籤中寫入點擊事件,如btnOnClick()btnOnClick(event),編譯器需要做一些事情以確保均勻t處理程序接受正確的參數。所以,對於我剛剛提到的Button標籤,與"event"鍵對應的 值將如下所示:{"click":"__on_click"}。編譯器會創建一個新的函數調用__on_click,這可能是這樣的:

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

顯然,你轉換成UIComponentDescriptor後的.mxml,則應更換事件功能。

對於構造:

的.mxml文件不能有一個構造函數,但是編譯器會創建一個在。至於文件,其中包含了UIComponentDescriptor。構造函數也會爲它的變量做一些初始化。轉換爲.mxml文件時,需要在變量聲明後進行初始化。 例如:

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

你應該把它轉換成這樣:

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

所以最重的工作就是UIComponentDescriptor轉換成的.mxml標籤。這裏是一個簡單的Python腳本,可以幫助你做到這一點:

UIComponentDescriptor2XML

相關問題