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?
答案 0 :(得分: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的实际内容如何,这都应该有效。