2011-09-19 34 views
0
i have main Application which is Spark component 
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
        xmlns:s="library://ns.adobe.com/flex/spark" 
        minWidth="955" minHeight="600" initialize="initApp();" xmlns:layout="com.zycus.workflow.editor.view.layout.*"> 
     <fx:Declarations> 
      <!-- Place non-visual elements (e.g., services, value objects) here --> 
     </fx:Declarations> 

    <layout:LeftPanel id="leftPanel"> 

     </layout:LeftPanel> 
    </s:application> 

What i need is i want to access leftpanel of mail application in Asction Script class 
How can i do it? 

回答

1

你有幾個選項,我簡化了你的代碼,並固定一個錯字,並刪除你不包括對象的引用。 正如您在下面的代碼中看到的,您可以一直到topLevelApplication,或者在這種情況下,只需引用您已定義的ID。

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
      xmlns:s="library://ns.adobe.com/flex/spark" 
      minWidth="955" minHeight="600" initialize="initApp(event)" > 
<fx:Script> 
    <![CDATA[ 
     import mx.core.FlexGlobals; 
     import mx.events.FlexEvent; 



     protected function initApp(event:FlexEvent):void 
     { 
      // Either from the top, if in another class, or ... 
      var pnl:Panel = Panel(FlexGlobals.topLevelApplication.leftPanel); 
      pnl.width = 500; 
      // Directly, since we are in this context. 
      leftPanel.width = 500; 
     } 

    ]]> 
</fx:Script> 
<fx:Declarations> 
    <!-- Place non-visual elements (e.g., services, value objects) here --> 
</fx:Declarations> 

<s:Panel id="leftPanel"> 

</s:Panel> 
</s:Application> 

本示例在Flash Builder中運行。無論您的LeftPanel的實際內容如何,​​這都應該可以工作。