开发者

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:CustomDivideBox id="div1">

Custompanel.mxml

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

}

Please provide some sample code.

Thanks, Naveen


If you want a reference to the main application you can use:

FlexGlobals.topLevelApplication

In your case though you should listen to J_A_X.


Why do you need the id when you're already in the object? Use the 'this' operator within your custom component.

private function xxxx(){
  this.state = (this.state == CustomDividedBox.COLLAPSE ? CustomDividedBox.EXPAND : CustomDividedBox.COLLAPSE);
}

This is very basic OOP concepts and I suggest you read up on that.

EDIT: Oh wait, those are 2 different components. What you want to do is dispatch an event within Custompanel.mxml, which Main.mxml listens for and knows what to do in the other component:

Main.mxml

customPanel.addEventListener('someEvent', someEventHandler);

private function someEventHandler(e:Event):void
{
   div1.doSomething();
}

CustomPanel.mxml

private function xxxx(){
   this.dispatchEvent(new Event('someEvent'));
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜