Jay Roy
asked on
if-else condition in mxml
hi guys
I need to impliment an If - else condition in my mxml file to show and hide data.
The requirment is if 'username' is jay
i need to show <mx:Button label="Create new User" />
else if username is Marco i need to show <mx:Button label="Create new Admin" />
Are there any <mx: tags using which i can do that?
right now i have this
<mx:Script>
private function userHandler(event:ResultEv ent):void
{
user = event.result;
username = user.name
}
]]>
</mx:Script>
<mx:Form width="1094" height="2200">
<mx:HBox width="100%" >
<mx:Button label="Create new User" /> if username is jay show this , else hide it
</mx:HBox>
<mx:HBox width="100%" >
<mx:Button label="Create new Admin" /> if username is marco show this , else hide it
</mx:HBox>
</mx:Form>
thanks for any help
I need to impliment an If - else condition in my mxml file to show and hide data.
The requirment is if 'username' is jay
i need to show <mx:Button label="Create new User" />
else if username is Marco i need to show <mx:Button label="Create new Admin" />
Are there any <mx: tags using which i can do that?
right now i have this
<mx:Script>
private function userHandler(event:ResultEv
{
user = event.result;
username = user.name
}
]]>
</mx:Script>
<mx:Form width="1094" height="2200">
<mx:HBox width="100%" >
<mx:Button label="Create new User" /> if username is jay show this , else hide it
</mx:HBox>
<mx:HBox width="100%" >
<mx:Button label="Create new Admin" /> if username is marco show this , else hide it
</mx:HBox>
</mx:Form>
thanks for any help
ASKER
thanks for the response
>>visible="{username == 'jay'}"/
I dont want to use the visible attribute because it creates empty space. Here is my exact code which uses visible:
<mx:Form width="1094" height="2200">
<mx:HBox width="100%" horizontalAlign="center" direction="horizontal"
paddingLeft="10" paddingRight="10" visible="{username == 'jay'}" >
<projectNav:MagnifyingButt on label="New "/>
<projectNav:MagnifyingButt on label="Delete"/>
<projectNav:MagnifyingButt on label="Copy "/>
<projectNav:MagnifyingButt on label="Send to LEAD"/>
</mx:HBox>
<mx:HBox width="100%" horizontalAlign="center" direction="horizontal"
paddingLeft="10" paddingRight="10" visible="{username == 'marco'}" >
<projectNav:MagnifyingButt on label="Approve"/>
<projectNav:MagnifyingButt on label="Reject"/>
</mx:HBox>
</mx:form>
now whenever user marco logs in there will be a big blank space caused by the First <mx:HBOX> .
That is why i dint want to use visible. Is there anyway we avoid that whitespace ?
thanks
>>visible="{username == 'jay'}"/
I dont want to use the visible attribute because it creates empty space. Here is my exact code which uses visible:
<mx:Form width="1094" height="2200">
<mx:HBox width="100%" horizontalAlign="center" direction="horizontal"
paddingLeft="10" paddingRight="10" visible="{username == 'jay'}" >
<projectNav:MagnifyingButt
<projectNav:MagnifyingButt
<projectNav:MagnifyingButt
<projectNav:MagnifyingButt
</mx:HBox>
<mx:HBox width="100%" horizontalAlign="center" direction="horizontal"
paddingLeft="10" paddingRight="10" visible="{username == 'marco'}" >
<projectNav:MagnifyingButt
<projectNav:MagnifyingButt
</mx:HBox>
</mx:form>
now whenever user marco logs in there will be a big blank space caused by the First <mx:HBOX> .
That is why i dint want to use visible. Is there anyway we avoid that whitespace ?
thanks
Yeah, just make the width contingent on the user name as well. There's a little trick here where the NaN (not-a-number) expression lets the component have its default width. You can do the same with height if necessary:
<mx:HBox width="100%" >
<mx:Button label="Create new User" width="{username == 'jay'?NaN:0}" visible="{username == 'jay'}"/>
<mx:Button label="Create new Admin" width="{username == 'macro'?NaN:0}" visible="{username == 'macro'}"/>
</mx:HBox>
<mx:HBox width="100%" >
<mx:Button label="Create new User" width="{username == 'jay'?NaN:0}" visible="{username == 'jay'}"/>
<mx:Button label="Create new Admin" width="{username == 'macro'?NaN:0}" visible="{username == 'macro'}"/>
</mx:HBox>
Sorry, I missed your updated code there. You could do this or use states.
<mx:HBox width="100%" horizontalAlign="center" direction="horizontal"
paddingLeft="10" paddingRight="10" visible="{username == 'jay'}" height="{username == 'jay'?NaN:0}" >
<projectNav:MagnifyingButton label="New "/>
<projectNav:MagnifyingButton label="Delete"/>
<projectNav:MagnifyingButton label="Copy "/>
<projectNav:MagnifyingButton label="Send to LEAD"/>
</mx:HBox>
<mx:HBox width="100%" horizontalAlign="center" direction="horizontal"
paddingLeft="10" paddingRight="10" visible="{username == 'marco'}" height="{username == 'jay'?NaN:0}">
<projectNav:MagnifyingButton label="Approve"/>
<projectNav:MagnifyingButton label="Reject"/>
</mx:HBox>
ASKER
ok cool thanks
one question
>>height="{username == 'jay'?NaN:0}"
User is not jay height is zero and if user is Jay what is the height ?
one question
>>height="{username == 'jay'?NaN:0}"
User is not jay height is zero and if user is Jay what is the height ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks, that helps. Can you please help me with my next question...
https://www.experts-exchange.com/questions/26865398/removing-redundancy-in-mxml.html
https://www.experts-exchange.com/questions/26865398/removing-redundancy-in-mxml.html
Open in new window