10 Replies Latest reply on Jul 31, 2009 1:31 PM by Jerry62712

    How do I: Loop through Application objects

    Jerry62712 Level 1

      How would I loop through the application object?  My goal is to see if the object is a label and change its font size.

       

      pseudocode would look like this:

       

       

      function setsize(change int) {

        for each obj in application {

          if obj is of type label {

            set font size to font size + change

          }

        }

      }

       

      Once I got that working, I'd add other objects that display text.  The "change" would be a number to increase (positive) or decrease (negative) the size.

       

      Thanks,

      Jerry

        • 1. Re: How do I: Loop through Application objects
          babo_ya Level 3

          Look into:

           

          import flash.utils.getDefinitionByName;
          import flash.utils.getQualifiedClassName;

           

          BaBo,

          • 2. Re: How do I: Loop through Application objects
            Gregory Lafrance Level 6

            If this post answered your question or helped, please mark it as such.

             

            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
              creationComplete="init();">
              <mx:Script>
                <![CDATA[
                  import mx.controls.Label;
                  private function init():void{
                    for each(var obj:Object in this.getChildren()){
                      if(obj is Label){
                        trace("It is a Label: " + obj.toString());
                      }
                    }
                  }
                ]]>
              </mx:Script>
              <mx:Button label="Btn1"/>
              <mx:ComboBox/>
              <mx:Label text="Lbl1"/>
              <mx:Button label="Btn2"/>
              <mx:Label text="Lbl2"/>
            </mx:Application>

            • 3. Re: How do I: Loop through Application objects
              Jerry62712 Level 1

              Looks very promising.  I'm assuming "this" in this case will represent the application.

               

              Is there any problem with components with this (no pun intended)?

              • 4. Re: How do I: Loop through Application objects
                Gregory Lafrance Level 6

                That's right, in this case "this" means the application.

                 

                Components in the application will not be parsed (meaning this is not recursive), so you might have to have this loop inside your components, or somehow detect a component and call a generic function in which you put this loop.

                 

                If this post answered your question or helped, please mark it as such.

                • 5. Re: How do I: Loop through Application objects
                  Jerry62712 Level 1

                  On a related question.  Say I find a label.  Then I change its font size like this:

                          for each ( var obj:Object in this.getChildren() ) {
                              if ( obj is Label ) {
                                  trace("**Testing** label: " + obj.toString());
                                  var newSize = obj.getStyle("fontSize") + getAmount();
                                  obj.setStyle("fontSize", amount);
                              }
                          }

                   

                  This will change the amount of space it takes.  Would I put the text in a container (perhaps a HBox, Canvas,...) and not have them have an "x" and "y" dimension?  What I'm trying to avoid is hardcoding size changes for the labels so they don't lay on top of eachother.

                   

                  Further, it seems that some containers will propagate the change and others will not.  "Panel" seemed to (on the base state), but didn't seem to on the other (result state) one.  I might not need every label if I can go after a container.

                  • 6. Re: How do I: Loop through Application objects
                    Gregory Lafrance Level 6

                    That's right. It is best practice to use auto-layout containers like HBox.

                     

                    If this post answered your question or helped, please mark it as such.

                    • 7. Re: How do I: Loop through Application objects
                      Jerry62712 Level 1

                      I have this:

                                <mx:HBox id="resultTextBox"
                                    width="100%"
                                    verticalScrollPolicy="off" horizontalScrollPolicy="auto">
                                    <mx:Label id="resultPotentialResultsLabel"
                                        text="Food Stamp potential eligibility for household, estimated monthly benefit amount "
                                        styleName="textNormal"
                                        toolTip="Results message"
                                        tabIndex="200" tabEnabled="true"  fontSize="40"/>
                                    <mx:Text id="resultPotentialResultsData"
                                        styleName="resultNumberNormal"
                                        toolTip="Final results"
                                        tabIndex="202" tabEnabled="true" />
                                </mx:HBox>

                       

                      When I expand the font size it pushes the "resultPotentialResutsData" to limbo.  I tried adding the horizonal scroll bar to allow the user to still see the results,  The scroll doesn't appear.

                       

                      1) is there a way to get the box to expand to fix the content?

                      2) is there a way to get the scroll bar to appear when needed?

                      3) is there a way to wrap the text (in this case the second field) in the HBox?

                      • 8. Re: How do I: Loop through Application objects
                        Gregory Lafrance Level 6

                        But resultPotentialResultsData has no text, so you won't see it anyway.

                        • 9. Re: How do I: Loop through Application objects
                          Jerry62712 Level 1

                          As I suspect you already know, I insert data into the text based on the results of a lot of calculations, so I still have the problem.

                           

                          BTW, I started a reply at 2:10 (local - CDT) and was going to include the URL for our application as currently written in java.  But I'm still waiting for the link box to open so I wrote the reply here.  If the box opens before I go home in an hour I'll send the URL.  If not, I'll just close the computer down and go home.

                           

                          Why is it so slow here?

                          • 10. Re: How do I: Loop through Application objects
                            Jerry62712 Level 1

                            I assign a value to it in ActionScript.  For a non-Flex example of the application, go to here

                             

                            Whoops, no URL.  The box came back in just over an hour and it allowed me to enter the URL, but then it wouldn't do anything with it.  Sigh.