Link to home
Start Free TrialLog in
Avatar of alamflex
alamflex

asked on

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

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
ASKER CERTIFIED SOLUTION
Avatar of dgofman
dgofman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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