dcsimg
A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: How to abort a tab change in TabNavigator.

  1. #1
    Junior Member
    Join Date
    Jan 2008
    Posts
    7

    How to abort a tab change in TabNavigator.

    I was wondering if someone knows how to do what is asked in the title. I have tried setting selectedIndex to the tab I really want them to stay on and that tabs contents aredisplayed, the problem is that the actual tab shown as selected is the one I clicked, NOT the one whose details are actually being shown! It appears that the default behavior is to highlight what was clicked, not what is selected.

    what exactly i'm trying to do is:
    I've two tabs- the first one contains a datagrid with users details...so when I double click on a record, it takes me to the second tab which contains a form to change the details of the selected user. Now, the problem is if I navigate away from the second tab back to the first tab without saving the details, i want the application to show me an alert warning me to save the data...and keeps me in the same tab...

    Thanks in advance for any help / insight.

  2. #2
    Junior Member
    Join Date
    Jan 2008
    Posts
    7
    i found a blog post on how to solve this:
    http://natescodevault.com/?p=43&cpage=1

    But the problem now is the tabnavigator wont respond for MOUSEEVENT.CLICK but it does respond for all the other events like MOUSEUP,MOUSEDOWN...
    I've created a sample app. following is the code for it:
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="fnCreate()" viewSourceURL="srcview/index.html">
    <mx:Script>
        <![CDATA[
            import mx.controls.Alert;
            import mx.controls.TabBar;
            import mx.events.*;
            import flash.events.MouseEvent
            public function fnCreate():void
            {
                
                adt.addEventListener(MouseEvent.CLICK, onTabClick, true);
                //adt.addEventListener(MouseEvent.MOUSE_DOWN, onTabClick, true);
                //addEventListener(MouseEvent.MOUSE_UP, onTabClick, true);
                //addEventListener(MouseEvent.MOUSE_OVER, onTabClick, true);
                adt.removeEventListener(MouseEvent.CLICK, onTabClick, true);
            }
                private function onTabClick(event:Event):void 
                {
                    
            if (event.target.parent is TabBar) {
                Alert.show("EVE:"+event.type+"___"+event.target.parent);
                var selectedIndex:uint= TabBar(event.target.parent).getChildIndex(event.target as DisplayObject);
                var isValid:Boolean = validateUserInfo();
    
                if (!isValid) {
                    event.stopImmediatePropagation();
                    event.preventDefault();
                }
            }
        }
        private function validateUserInfo():Boolean
        {
            //if(adt.selectedIndex==1)
            return false;
            //else
            //return false;
        }
        ]]>
    </mx:Script>
        <mx:TabNavigator id="adt" width="532" height="437" creationComplete="fnCreate()"  >
            <mx:Panel label="panel1">
                <mx:Label text="PANEL1"/>
            </mx:Panel>
            <mx:Panel label="panel2">
                <mx:Label text="PANEL2"/>
            </mx:Panel>
        </mx:TabNavigator>
    </mx:Application>
    demo of the above code here:
    http://ravimarella.com/tabNavigator/launch.html

    can anyone please help me in solving this???

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center