How to get id value of Main.mxml file to CustomPanel.mxml file?

alamflex
alamflex used Ask the Experts™
on
I have a method in CustomPanel.mxml and i need to use id which is available in Main.mxml

Below is my sample code

Main.mxml
-------------
<local:CustomDividedBox id="div1">

Custompanel.mxml
----------------------
private function xxxx(){
div1.state = (div1.state == CustomDividedBox.COLLAPSE ? CustomDividedBox.EXPAND : CustomDividedBox.COLLAPSE);

}

Plz provide some sample code.

Thanks,
Alam
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2011
Commented:
I think I understand what you want, looks like you are trying implementing toogle feature in CustomDividedBox what I think is good idea. So, add this function into your CustomDividedBox.as

public function toggle():void{
   state = (state == CustomDividedBox.COLLAPSE ? CustomDividedBox.EXPAND : CustomDividedBox.COLLAPSE);
}

Now you can call ths function anytime and apply for any Divided boxes

private function contextMenuItem_propertiesSelect(evt:ContextMenuEvent):void {
    div1.toggle();
}
Hi,

if your Custompanel is used as component in Main.mxml then you could pass a reference to the div1 CustomDividedBox to your Custompanel.

Sample code for Main.mxml
...
<local:CustomDividedBox id="div1"/>
<local:Custompanel id="panel" box="{div1}"/>
---

Open in new window


You need to add a variable "box" to your Custompanel class and use this in your xxxx function:
...
	<mx:Script>
		<![CDATA[
			import CustomDividedBox;
			
			public var box:CustomDividedBox;
			
			private function xxxx():void {
				box.state = (box.state == CustomDividedBox.COLLAPSE) ? 
								CustomDividedBox.EXPAND : 
								CustomDividedBox.COLLAPSE;
			}
		]]>
	</mx:Script>
...

Open in new window


Just a question: are you using states in your CustomDividedBox and want to change the state of the box? Then you would have to use the property box.currentState instead of box.state.

Cheers

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial