5/3/2010 2:27:32 AM
Title:
How to access child component ids by using modules
Hi,
How to access child component id by using modules in parent application,
Please help me,
Thanks & Regards,
K.V.Ramakrishna
Inder
Points: 2880
Posts:0
5/3/2010 5:27:33 AM
to access a child component of a module you can check this example.
Below is my main application mxml where I am loading Module1.mxml as my module. We are accessing the label from module and tracing the text of label.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="1024" minHeight="768" applicationComplete="initApp()">
<mx:Script>
<![CDATA[
import mx.controls.Label;
import mx.events.ModuleEvent;
import mx.modules.IModuleInfo;
import mx.modules.ModuleManager;
public var info:IModuleInfo;
public function initApp():void {
info = ModuleManager.getModule("Module1.swf");
info.addEventListener(ModuleEvent.READY,
modEventHandler);
info.load();
}
private function modEventHandler(e:ModuleEvent):void
{
vb1.addChild(info.factory.create() as Module1);
var moduleRoot=vb1.getChildAt(0) as DisplayObject
//we are accessing the lable from module
trace(moduleRoot.getChildByName("myLabel").text);
}
]]>
</mx:Script>
<mx:VBox id="vb1" width="100%" height="100%">
</mx:VBox>
</mx:Application>
Module mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Module xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="400" height="300" >
<mx:Script>
<![CDATA[
import mx.events.FlexEvent;
]]>
</mx:Script>
<mx:Label name="myLabel" x="68" y="57" text="This is a loaded module label"/>
</mx:Module>
5/3/2010 9:35:43 PM
Hi,
This is my main application
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:components="components.*" backgroundGradientAlphas="[0.0, 0.0]" borderThickness="0" cornerRadius="0" backgroundAlpha="1.0" alpha="1.0"
>
<mx:VBox width="100%" height="100%" verticalGap="0">
<components:APQPHeader />
<mx:Script>
<![CDATA[
import mx.controls.DataGrid;
import mx.controls.Label;
[Bindable]
var lblTitle:Label = new Label();
public function AddProjectNameTag( ProjectTitle:String):void
{
nn.label = ProjectTitle;
}
private function changeHandler(event:Event):void
{
try{
parentApplication.ListMyProjects.dgAPQPProjectList.setStyle("fontSize", ComboBox(event.currentTarget).selectedItem.value);
}
catch(e:Error)
{
}
}
]]>
</mx:Script>
<mx:ApplicationControlBar id="mainApplicationTabBar" width="100%" >
<mx:LinkBar dataProvider="{VS1}" id="mnuMain"/>
<mx:Spacer width="100%" />
<mx:ComboBox id="cmb_fontSize" textAlign="center" useHandCursor="true" buttonMode="true" change="changeHandler(event)" close="{ListMyProjects.dgAPQPProjectList.setStyle('fontSize',cmb_fontSize.selectedItem.value)}" height="29" width="104" fontWeight="bold">
<mx:ArrayCollection>
<mx:Object label='A 10px' value='10'/>
<mx:Object label='A 12px' value='12'/>
<mx:Object label='A 14px' value='14'/>
</mx:ArrayCollection>
</mx:ComboBox>
</mx:ApplicationControlBar>
<mx:ViewStack id="VS1" width="100%" height="100%" >
<mx:Canvas id="canHome" label="Home" width="100%" height="100%">
<mx:ModuleLoader url="Home.swf" width="100%" height="100%" id="modHome"/>
</mx:Canvas>
<mx:VBox id="nn" label="" />
<mx:Canvas label="Admin" width="100%" height="100%" >
<mx:ModuleLoader width="100%" height="100%" url="Admin.swf" id="modAdmin"/>
</mx:Canvas>
<mx:Canvas label="Help & Support" width="100%" height="400">
<mx:ModuleLoader width="100%" height="100%" url="HelpandSupport.swf"/>
</mx:Canvas>
</mx:ViewStack>
<components:APQPFooter textAlign="left"/>
</mx:VBox>
</mx:Application>
This is my Child Application, how to get the datagrid , please check my code
<?xml version="1.0" encoding="utf-8"?>
<mx:Module xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%" xmlns:apqpprojectservice="services.apqpprojectservice.*">
<mx:Metadata>
[Event(name="NewItemClicked", type="flash.events.Event")]
</mx:Metadata>
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.controls.Label;
import mx.events.FlexEvent;
import mx.events.MenuEvent;
var newMenu:Array = [
{ MenuItem: "New APQP Project" },
{ MenuItem: "New PPAP Project" }
];
protected function dgAPQPProjectList_creationCompleteHandler(event:FlexEvent):void
{
GetAllProjectsResult.token = aPQPProjectService.GetAllProjects();
}
protected function mnuNew_itemClickHandler(event:MenuEvent):void
{
if ( event.label == "New APQP Project")
{
parentApplication.modHome.child.modMyProjects.child.ShowNewProject("New APQP Project");
}
}
protected function dgAPQPProjectList_doubleClickHandler(event:MouseEvent):void
{
parentApplication.AddProjectNameTag( dgAPQPProjectList.selectedItem.Title);
// TODO Auto-generated method stub
}
]]>
</mx:Script>
<mx:VBox width="100%" height="100%">
<mx:HBox width="100%" cornerRadius="4" borderStyle="solid" verticalAlign="middle" horizontalGap="5" height="40">
<mx:Spacer width="1%"/>
<mx:PopUpMenuButton id="mnuNew" label="New Projects" dataProvider="{newMenu}" labelField="MenuItem" showRoot="false" itemClick="mnuNew_itemClickHandler(event)" />
<mx:Spacer width="100%"/>
<mx:TextInput borderStyle="solid" cornerRadius="3" width="220" height="30"/>
<mx:Image id="loader1" />
<mx:Spacer width="1%"/>
</mx:HBox>
<mx:HBox width="100%" height="100%" >
<mx:HBox height="100%" borderStyle="solid" horizontalGap="5" verticalGap="5" cornerRadius="5">
<mx:Spacer />
<mx:VBox>
<mx:Spacer>
</mx:Spacer>
<mx:ToggleButtonBar dataProvider="viewstack1" direction="vertical" width="160" height="75">
</mx:ToggleButtonBar>
</mx:VBox>
<mx:Spacer />
</mx:HBox>
<mx:HBox width="100%" height="100%" borderStyle="solid" horizontalGap="5" verticalGap="5">
<mx:ViewStack id="viewstack1" width="100%" height="100%">
<mx:Canvas label="APQP Projects" width="100%" height="100%">
<mx:DataGrid id="dgAPQPProjectList" creationComplete="dgAPQPProjectList_creationCompleteHandler(event)" dataProvider="{GetAllProjectsResult.lastResult}" doubleClickEnabled="true" doubleClick="dgAPQPProjectList_doubleClickHandler(event)" width="100%" height="100%">
<mx:columns>
<mx:DataGridColumn headerText="*" width="25"/>
<mx:DataGridColumn headerText="Project Id" dataField="Id"/>
<mx:DataGridColumn headerText="Project Title" dataField="Title"/>
<mx:DataGridColumn headerText="Part Number" dataField="PartNumber"/>
<mx:DataGridColumn headerText="Part Description" dataField="PartDescription"/>
<mx:DataGridColumn headerText="ECN" dataField="ECN"/>
<mx:DataGridColumn headerText="Supplier Id" dataField="SupplierCode"/>
<mx:DataGridColumn headerText="Supplier Name" dataField="SupplierName"/>
<mx:DataGridColumn headerText="Receiving Facility" dataField="ReceivingFacility"/>
</mx:columns>
</mx:DataGrid>
</mx:Canvas>
</mx:ViewStack>
</mx:HBox>
</mx:HBox>
</mx:VBox>
<mx:CallResponder id="GetAllProjectsResult"/>
<apqpprojectservice:APQPProjectService id="aPQPProjectService" fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" showBusyCursor="true"/>
</mx:Module>
please reply the answer , how to get the datagrid id
5/3/2010 9:37:45 PM
Hi,
From above code, Whenever I click the combo box , the datagrid font size will be increased or decreased, So please help me,
Thanks & Regards,
K.V.Ramakrishna
5/5/2010 3:33:31 AM
To access your module from your main application you can use
//modAdmin is canvas container in which adminModule (adminModule.swf) is loaded using ModuleLoader tag
(modAdmin.child as adminModule)
// to access the compoents inside like dataGrid "dgAPQPProjectList" use
(modAdmin.child as adminModule).dgAPQPProjectList
//to change font size of grid write this on comboChange
(modAdmin.child as adminModule).dgAPQPProjectList.setStyle("fontSize", ComboBox(event.currentTarget).selectedItem.value);