tags:

views:

32

answers:

3

I have a vertical tab-bar with 4 items with different sub tabs. All the four items use data from a single xml file, which is a big file. When the user clicks on a tab, while the data is being loaded this error is shown.

TypeError: Error #1009: Cannot access a property or method of a null object reference.

I want to disable all the tabs while the xml file is being loaded.

A: 

you can display an overlay component which will block all events. and that overlay can be removed once all data is loaded.

to make it more cool overlay can have background partially transparent.

sfaiz
+1  A: 

You can set the main application to disabled; which should disable all children. Use the enabled property and set it to false. IF you want to stop mouse interaction too, be sure to set the mouseEnabled property to false.

www.Flextras.com
+1, I was thinking the same thing.
Wade Mueller
I have tried adding the attribute `enabled="false"` to the application, i do not see any affect. Is that the right place to add the property?
Anji
@Anji yes, I would have expected that to be the right place to add it. According to documentation that should disable all of it's children. I haven't tried it at the application level, though.
www.Flextras.com
@www.Flextras.com It was my bad, made changes to the wrong file. It works Thanks.
Anji
Great, glad to hear it.
www.Flextras.com
A: 

Control the enabled/disabled property by binding to getters and setters on the data you're working with. For example:

<mx:Script>
    <![CDATA[
        [Bindable]
        public var myParsedXML:Object;

        private var _myData:Object;

        public function set myData(value:Object):void
        {
            //Check for null
            if(value)
            {
                myTabs.enabled = true;
            }
            else
            {
                myTabs.enabled = false;
            }
            _myData = value;
        }

        public function get myData(value:Object):void
        {
            return _myData;
        }
    ]]>
</mx:Script>
<mx:Binding source="myParsedXML" destination="myData" />
<mx:TabNavigator id="myTabs">
    <mx:VBox label="tab 1">

    </mx:VBox>
    <mx:VBox label="tab 2">

    </mx:VBox>
</mx:TabNavigator>    

Once you've created this property, you can bind to it and be sure that it will be notified when the data is set.

Dan Monego
Dan, I'm unclear how your code supports your answer. First, you did not make your property bindable with the Binadable metadata tag. Second, you have two set methods and no get method. [I think that was a typo]. Third, the first set method does not dispatch a "myDataChanged" event which will be used internally for Flex Binding. Finally, an object variable would not usually be bound to the Boolean property.
www.Flextras.com
@www.Flextras.com: This code represents a property on the view, which is why it is not bindable, does not produce a myDataChanged event, and is not bound to a boolean property. The double set was just sloppiness.
Dan Monego
@Dan Monego Your updated code block makes a lot more sense.
www.Flextras.com