[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

if-else condition in mxml

Posted on 2011-03-04
7
Medium Priority
?
2,685 Views
Last Modified: 2012-05-11
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:ResultEvent):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
0
Comment
Question by:royjayd
  • 4
  • 3
7 Comments
 
LVL 11

Expert Comment

by:petiex
ID: 35038994
This should work:

                  <mx:Script>
                  [Bindable]
                  private var username:String;
                  private function userHandler(event:ResultEvent):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" visible="{username == 'jay'}"/>      
          <mx:Button  label="Create new Admin" visible="{username == 'macro'}"/> 
        </mx:HBox>
                         
</mx:Form>

Open in new window

0
 

Author Comment

by:royjayd
ID: 35039783
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: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'}" >      
            <projectNav:MagnifyingButton label="Approve"/>
            <projectNav:MagnifyingButton 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


0
 
LVL 11

Expert Comment

by:petiex
ID: 35039954
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>
0
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 11

Expert Comment

by:petiex
ID: 35040020
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>

Open in new window

0
 

Author Comment

by:royjayd
ID: 35040354
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 ?
0
 
LVL 11

Accepted Solution

by:
petiex earned 2000 total points
ID: 35041373
Well, when you say height="NaN", it is sort of like saying "forget that I ever set the height at all." For an HBox, that means set the height big enough to contain its child components.
0
 

Author Comment

by:royjayd
ID: 35044007
thanks, that helps. Can you please help me with my next question...
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/Flex/Q_26865398.html
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

First things first - Preparation We need all the part for this install and it's much nicer to have them all on hand when you need them so here's what's required. Download Eclipse 3.5 32 bit (I like the Classic flavour) from here. (http://www.e…
Exchange administrators are always vigilant about Exchange crashes and disasters that are possible any time. It is quite essential to identify the symptoms of a possible Exchange issue and be prepared with a proper recovery plan. There are multiple…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question