views:

379

answers:

2

I have a combobox in a view that receives information about application state changes, and then is supposed to show or hide it's children based on the whole application state.

It receives state change messages, it traces the correct values, it does what it's supposed to do, however, it just doesn't seem to work. Essentially, all it needs to do is hide a combobox during one state, and show it again during another state.

Here is the code:

public function updateState(event:* = null):void {
        trace("Project Panel Updating State");
        switch(ApplicationData.getSelf().currentState) {
            case 'login':
                this.visible = false;
                break;
            case 'grid':
                this.visible = true;
                listProjects.includeInLayout = false;
                listProjects.visible = false;
                trace("ListProjects: " + listProjects.visible);
                listLang.visible = true;
                break;
            default:
                break;


        }
    }

Here is the MXML:

    <mx:HBox>
    <mx:Button id="btnLoad" x="422" y="84" label="Load" enabled="true" click="loadProject();"/>
    <mx:ComboBox id="listProjects" 
                x="652" 
                y="85" 
                editable="true" 
                change="listChange()" 
                color="#050CA8" 
                fontFamily="Arial" />   
    <mx:Label x="480" y="86" text="Language:" id="label3" fontFamily="Arial" />
    <mx:ComboBox id="listLang" 
                x="537" 
                y="84" 
                editable="true" 
                dataProvider="{langList}" 
                color="#050CA8" 
                fontFamily="Arial" 
                width="107" 
                change="listLangChange(event)"/>
    <mx:CheckBox x="830" y="84" label="Languages in English" id="langCheckbox" click='toggleLang()'/>
</mx:HBox>
+1  A: 

Have you tried changing

updateState(event:* = null):void

to this

updateState(event:Event = null):void

Im still looking into the event:* and everything I have found so far has Event instead of *. Will repost still looking

Justin Gregoire
Yeah, it could be that way, but :* is more or less the same. Though it won't really affect it, I still changed it.
That's what I wasn't sure about, I wasn't able to find anything that used, event:* figuring that you wanted to account for all event types. I had also found MouseEvent and others though.
Justin Gregoire
+2  A: 

It's not that clear form your code where and how the updateState function gets called, and to get any further into a solution I think I would need to see that. However, I think you may like to consider a different approach.

Have you tried using views instead of manually showing and hiding things and setting properties? I think you would have simpler code if you had a different view state for each of the cases in your switch, e.g. 'login' etc. Then all the showing hiding stuff becomes a design-time activity rather than run-time and all you have to do is set the current state.

If you matched your state names with your ApplicationData currentState values you may even be able to do away with the updateState function completely.

Simon
You are more or less right, the problem was that updateState was being called at the wrong time on creation of the component. So I simply placed the call in an init function that is called on creationComplete.
glad you sorted it out, but still think you would be better off with views.
Simon
I did eventually switch to that. It's a large project that was done in flex and is being refactored to AIR. It was in one large MXML file for the flex app, so deciding where to start revamping has been a tough one.