2010-03-11 67 views
0

我不得不重新格式化我的問題,因爲我意識到我使用的是不正確的flex方法。但仍然會出現類似問題:在flex中使用popupmanmanager時的隱式強制

 private function passForm():void { 


      PopUpManager.addPopUp(passTitleWindow, this, true); 
      PopUpManager.centerPopUp(passTitleWindow); 


     } 

          <s:Button includeIn="Detail" x="10" y="329" 
            id= "btn1" 
            label="Pass" 
            click="passForm()" 
            visible="{hasScreen}" /> 

我點擊並彈出不顯示。

回答

1

你不能基於它的id實例化一個項目。把你的TitleWindow變成另一個類並實例化它。

PassTitleWindow.mxml

<?xml version="1.0" encoding="utf-8"?> 
<mx:TitleWindow 
    xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    xmlns:mx="library://ns.adobe.com/flex/mx" 
    title="Pass" 
    layout="vertical" 
    width="480" 
    height="240" 
    titleStyleName="titleText" 
    backgroundColor="white" 
    backgroundAlpha="1.0" 
    borderColor="white" 
    borderAlpha="1.0" 
    cornerRadius="0" 
    showCloseButton="true" 
    implements="mx.core.IDataRenderer"> 

    <fx:Script> 
     <![CDATA[ 

      private var _data:Object; 
      [Bindable(event="dataChange")] 
      /** 
      * implementing mx.core.IDataRenderer. 
      * Set this value from outside 
      */ 
      public function get data():Object 
      { 
       return _data; 
      } 

      /** 
      * @private 
      */ 
      public function set data(value:Object):void 
      { 
       if (_data == value) 
        return; 
       _data = value; 
       dispatchEvent(new Event("dataChange")); 
      } 
     ]]> 
    </fx:Script> 

    <mx:Text text="Please fill out the following criteria and then click continue." 
     width="100%" 
     styleName="headingText"/> 

    <mx:Form x="-12" y="150" id="passView"> 

     <mx:FormItem label="Age" > 
      <s:TextInput id="ageTextInput" "@{data.age}"/> 
     </mx:FormItem> 
     <mx:FormItem label="Grade" > 
      <s:TextInput id="gradeTextInput"/> 
     </mx:FormItem> 

    </mx:Form> 

</mx:TitleWindow> 

SampleApp.mxml

<?xml version="1.0" encoding="utf-8"?> 
<s:Application 
    xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    xmlns:mx="library://ns.adobe.com/flex/mx" 
    creationComplete="creationCompleteHandler()"> 

    <fx:Script> 
     <![CDATA[ 

      import mx.managers.PopUpManager; 

      protected var passWindow:PassTitleWindow = new PassTitleWindow; 

      protected function creationCompleteHandler():void 
      { 
       createForm(); 
      } 

      protected function createForm():void 
      { 
       passWindow = PopUpManager.createPopUp(this, PassTitleWindow, true) as PassTitleWindow; 
       passWindow.data = studentGrid.selectedItem; 
       PopUpManager.centerPopUp(passWindow); 
      } 
     ]]> 
    </fx:Script> 

</s:Application> 

希望幫助, 蘭斯

+0

感謝響應。我遇到的問題是,在另一個組件中,我收到的學生網格是未定義的方法: 原因爲什麼studentsgrid在應用程序中定義,而不是組件,我猜組件不能與應用程序中的數據網格通信。 – JohnMerlino 2010-03-11 01:17:21

+0

我明白了。最好的做法是分離數據,以便項目渲染器不必引用其父項。你可以通過實現IDataRenderer(一個獲取/設置「數據」的方法),並將數據設置爲選定的項目。我已經更新了代碼來證明這一點。讓我知道這是否有幫助。 – 2010-03-12 10:43:24

+0

終於得到它來更新正確的項目,禮貌您的意見和這個鏈接:http://livedocs.adobe.com/flex/3/html/help.html?content=cellrenderer_7.html。我不認爲我完全理解這一行:dispatchEvent(new Event(「dataChange」))。但我會再次閱讀這篇文章,看看它是否提供了任何見解。感謝您帶領我走向正確的道路。 – JohnMerlino 2010-03-13 19:27:20