2 Replies Latest reply on Nov 12, 2010 1:12 AM by athiroy

    Alignment Center in Label

    athiroy Level 1

      hi
      i am working in flex 4.

       

      i use one string varaible named str and i stored
      str="Would  become computer literal to be able to alll of its things in six months with one computer."

       

      i want to split the str variable into fline and sline. I used to split str variable using the following lines
                 
              if(str.length>50)
                      {
                      fline= str.substring(0, str.lastIndexOf(" ", 50));
                      sline =  str.substring(str.lastIndexOf(" ", 50) +  1);
                      firstLine();
                      //Alert.show(sline);
                      }
                      else
                      {
                          fline=str;
                          sline=" ";
                          firstLine();
                         
                      }
                     
      Then i want to create label of each words using this lines

       


      private function firstLine():void
              {
                 //Alert.show(fline);
                  var l1:Number=fline.length;
                  //    Alert.show(l1.toString());
                 
                  myarr=fline.split(" ");
                  myarr1=sline.split(" ");
                 
                  //var l1:Number=Number(l);
                  inputValue = myarr.length;
                  //Alert.show(inputValue.toString());
                  for(var intLoop:int=0;intLoop<inputValue;intLoop++)
                  {
                      lbl = new Label();
                      lbl.id="l"+intLoop;
                      lbl.text = myarr[intLoop];
                      lbl1 = new Label();
                      lbl1.id="l"+intLoop;
                      lbl1.text = myarr1[intLoop];
             
                     
                      lbl.addEventListener(MouseEvent.MOUSE_OVER, onLabelOver);
                      lbl.addEventListener(MouseEvent.CLICK, onLabelClick);
                      lbl.addEventListener(MouseEvent.MOUSE_OUT, onLabelOut);
                      lbl.styleName="hai1";
                         
                      lbl1.addEventListener(MouseEvent.MOUSE_OVER, onLabelOver);
                      lbl1.addEventListener(MouseEvent.CLICK, onLabelClick);
                      lbl1.addEventListener(MouseEvent.MOUSE_OUT, onLabelOut);
                      lbl1.styleName="hai1";
                     
                     
                      labelBox.addChild(lbl);
                      labelBox1.addChild(lbl1);
                 
                 
                         
                      }
                      labelBox.styleName="lblalign";
                     
                     
                  }

       

      after i split the words add the words(lbl) into labelBox and labelBox1.
      Here the LabelBox and LabelBox1

       

      <mx:HBox id="labelBox" x="54" y="263" width="389" height="18" color="#FFFFFF" alpha="0.40" backgroundColor="#000101"  >
              </mx:HBox>
              <mx:HBox id="labelBox1" width="389" height="20" color="#FFFFFF" alpha="0.40" backgroundColor="#000000" x="54" y="280">
                 
              </mx:HBox>

       


      This is displayed as follows
      Would  become computer literal to be able to alll
      of its things in six months with one computer

       

      but my requirement is align this line to center.

       

      Would  become computer literal to be able to alll
      of its things in six months with one computer

       

      Is it possible.
      if possible means give some ideas to me.

       

      regards
      athi