[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

if-else condition in mxml

Posted on 2011-03-04
7
Medium Priority
?
2,648 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

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…
An overview of cyber security, cyber crime, and personal protection against hackers. Includes a brief summary of the Equifax breach and why everyone should be aware of it. Other subjects include: how cyber security has failed to advance with technol…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

656 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