1

In my Flex 4.6 web application I use mainly spark components, but there is also an mx-component - a PopUpButton extended by me (the source code is below).

Users report problems with that button, but I can't reproduce any - since weeks.

I've tried replacing mx:Menu attached to it by a s:List but it hasn't changed anything. I suspect there is a "null pointer exception" or some other failure, that I don't hit when testing myself...

My question is: why does Flash Builder reports warning about my custom button as if its methods would be private or not present?

enter image description here

Can anybody please spot the reason?

My main App.mxml:

<?xml version="1.0" encoding="utf-8"?>
<s:Application  
    xmlns:fx="http://ns.adobe.com/mxml/2009"
    xmlns:s="library://ns.adobe.com/flex/spark"
    xmlns:mx="library://ns.adobe.com/flex/mx"
    xmlns:comps="*">

    <fx:Script>
        <![CDATA[
                   _auxBtn.update(obj.aux);
                    ......
                   _auxBtn.disable();
        ]]>
    </fx:Script>

    <comps:AuxButton id="_auxBtn" enabled.normal="false" enabled.ingame="false" aux="handleAux(event)" />

My custom button AuxButton.mxml:

<?xml version="1.0" encoding="utf-8"?>
<mx:PopUpButton
    xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    xmlns:mx="library://ns.adobe.com/flex/mx"
    popUp="{_list}"
    initialize="init(event)">

    <fx:Metadata> 
        [Event(name="aux", type="PrefEvent")] 
    </fx:Metadata>

    <fx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            import mx.events.FlexEvent;
            import mx.utils.ObjectUtil;
            import spark.components.List;

            private const EXACT:String = 'Своя игра';
            private const REVEAL:String = 'Показать';

            private var _str:String;

            [Bindable]
            private var _data:ArrayCollection = new ArrayCollection();

            [Bindable]
            private var _list:List = new List();

            private function init(event:FlexEvent):void {
                _list.dataProvider = _data;
                _list.addEventListener('click', handleList);
                addEventListener('click', handleClick);
            }

            public function update(aux:Array):void {
                var found:Boolean;

                // nothing has changed
                if (ObjectUtil.compare(_data.source, aux, 0) == 0)
                    return;

                if (aux == null || aux.length == 0) {
                    disable();
                    return;
                }

                _data.removeAll();
                for each (var obj:Object in aux) {
                    _data.addItem(obj);

                    if (!_str) {
                        if (EXACT == obj['label']) {
                            _str  = obj['event'];
                            label = obj['label'];
                            found = true;
                        } else if (REVEAL == obj['label']) {
                            _str  = obj['event'];
                            label = obj['label'];
                            found = true;
                        }
                    } else if (_str == obj['event']) {
                            found = true;
                    }
                }

                if (!found) {
                    _str  = _data[0].event;
                    label = _data[0].label;
                }

                enabled = true;
            }

            private function handleList(event:MouseEvent):void {
                var index:int = _list.selectedIndex;
                if (index >= 0 && index < _data.length) {
                    _str  = _data[index].event;
                    label = _data[index].label;
                }
                close();
            }           

            private function handleClick(event:MouseEvent):void {
                dispatchEvent(new PrefEvent(PrefEvent.AUX, _str));
                disable();
            }

            public function disable():void {
                _data.removeAll();
                enabled = false;
                _str    = null;
                label   = '';
            }
        ]]>
    </fx:Script>
</mx:PopUpButton>
Alexander Farber
  • 21,519
  • 75
  • 241
  • 416
  • I copied your code into a new project and didn't get the warnings. I don't think there's anything wrong with the code you posted. Have you tried removing chunks of your app until the warnings go away? It might help you track down where the issue actually is. – Wesley Petrowski Mar 16 '12 at 21:30
  • 1
    It could also be that the warnings are spurious - I've had many strange things go away after doing a "clean" on the project. – Wesley Petrowski Mar 16 '12 at 21:32

1 Answers1

1

Don't worry about Flash Builder warnings, sometimes it has difficulties analyzing custom mx extended code (even spark sometimes!). If it runs it's okay, warnings will eventually go away after a clean or a FB restart.

You can also try to reproduce same feature using a mix of spark component, depending on a feature, it is maybe the best thing to do.

Stay assured, I pasted your code in my Flash Builder (and removed the PrefEvent), there are no warnings at all on my computer :)

For the error you users are reporting, you should give us more detail so we can try to help.

Cheers

a.s.t.r.o
  • 3,261
  • 5
  • 34
  • 41