Padma,

 

First define your component and save it as “mail.mxm”. By the way, I do use Pascal case names for Components because they will be transformed into classes and all my classes have a capital first letter.

 

Example code for mail.mxml:

 

<?xml version="1.0" encoding="utf-8"?>

<mx:Canvas xmlns:mx="http://www.macromedia.com/2005/mxml" xmlns="*">

      <mx:TabNavigator id="MyTabNavigator" x="0" y="0" width="500" height="300">

            <mx:Canvas label="Tab 1" width="100%" height="100%">

            </mx:Canvas>

            <mx:Canvas label="Tab 2" width="100%" height="100%">

            </mx:Canvas>

      </mx:TabNavigator>     

</mx:Canvas>

 

This is a pretty simple TabNavigator with two tabs. The TabNavigator class implements the change Event through inheritance from ViewStack. Make sure your TabNavigator has a value for the id attribute set so you can reference to the control from within your main application.

In your main appication (Main.mxml) include the component as seen below (<MyComponent:mail id=”MailComponent”/>. All you have to add is an event listener for the TabNavigator in your component. I do this in the initialization routine for main application which gets called via the onCreationComplete event of main.mxml.

MailComponent.MyTabNavigator.addEventListener(“change”, onChange);

adds an event listener to the TabNavigator control in the component. It effectively says that if this component fires the “change” event, the onChange() method in main.mxml should handle it. The last step is to define the handler in main.mxml. In the following example onChange(_e:Event):Void simply traces the change to the console.

<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.macromedia.com/2005/mxml" xmlns:MyComponent="*" creationComplete="onCreationComplete(event);">

 

      <mx:Script>

            <![CDATA[

                  private function onChange(_e:Event):Void

                  {

                        flash.util.trace("Tab has changed.");

                  }

                 

                  private function onCreationComplete(_e:Event):Void

                  {

                        MailComponent.MyTabNavigator.addEventListener("change", onChange);

                  }

            ]]>

      </mx:Script>

      <mx:Canvas width="600" height="400">

            <MyComponent:mail id="MailComponent"/>

      </mx:Canvas>

</mx:Application>

I hope this helps a bit.

Ralf Rottmann


From: flexcoders@yahoogroups.com [mailto:flexcoders@yahoogroups.com] On Behalf Of padma vathi
Sent: Montag, 5. Dezember 2005 08:56
To: flexcoders@yahoogroups.com
Subject: [flexcoders] how to handle an event dispatched by a tabnavigator component in main mxml

 

Hi

 i am using tabnavigator in my mail mxml file.i want to know how to handle  an event dispatched from  from a componenent of tab navigator to main mxml.

 

if any one know tell this it would be helpful

 

 

padma


Enjoy this Diwali with Y! India Click here


--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com




YAHOO! GROUPS LINKS




Reply via email to