9 Replies Latest reply on Jul 22, 2009 3:58 PM by Flex harUI

    conditionals

    dmfsantacruz Level 1

      I have a viewstack with two vboxes each one with a different color. I want to do a conditional (if then) in response to data coming in from an xml. I am a relative noob to flex and only know some actionscript 2

      I am more familiar with basic and this is how I would put it.

       

       

      if os_status = 0 then

           boxStack.selectedIndex = 0

      else

           boxStack.selectedIndex = 1

      endif

       

      where os_status is the field from the XML and boxStack is my viewstack.

       

      thanks!

        • 1. Re: conditionals
          Gregory Lafrance Level 6

          In Flex:

           

          if os_status = 0{

              boxStack.selectedIndex = 0;

          } else

              boxStack.selectedIndex = 1;

          }

           

          If this post answers your question or helps, please mark it as such.

          1 person found this helpful
          • 2. Re: conditionals
            dmfsantacruz Level 1

            That helps a lot, thanks Greg.

             

            The only thing Im not quite clear on yet is getting my arraycollection data into a form I can use. I am using an arraycollection to pull data from the XML httpservice which is coming from a PHP sql query. I am familiar with using arrays and accessing the individual data objects by referencing array[0] etc.

            With the arraycollection, I havent figured out how to reference individual data objects so I can make calculations and do conditionals.

             

            Heres a copy of the code

             

            <mx:Script>

            <![CDATA[

            import mx.controls.Text;

            import mx.controls.Label;

            import mx.collections.ArrayCollection;

            import mx.rpc.events.ResultEvent;

            [Bindable]

            private var omArray:ArrayCollection

            private function resultHandler(event:ResultEvent):void

            {

            omArray = event.result.response.data.row;

             

            }

            ]]>

            </mx:Script>

             

            <mx:HTTPService id="inventoryService"

            url="http://localhost/OMRON-debug/Inventory.php?method=FindAll"

            result="resultHandler(event)"/>

             

            • 3. Re: conditionals
              dmfsantacruz Level 1

              if anyone has any additional thoughts on this it would be greatly appreciated!

              • 4. Re: conditionals
                Gregory Lafrance Level 6

                You can loop through an ArrayCollection:

                 

                var ac:ArrayCollection = new ArrayCollection(["one", "two", "three", "four"]);

                 

                for each(var str:String in ac){

                    trace(str);

                }

                 

                ----- output -----

                one

                two

                three

                four

                 

                Or you can access individual elements of the ArrayCollection:

                 

                for(var a:uint=0; a<ac.length();a++){

                    trace(ac.getItemAt(a));

                }

                 

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

                1 person found this helpful
                • 5. Re: conditionals
                  dmfsantacruz Level 1

                  Greg,

                   

                  when running

                   

                  for(var a:uint=0; a<ac.length();a++){

                      trace(ac.getItemAt(a));

                  }

                   

                  I get [object Object] for all entries.

                  I also tried ac.getItemAt(a).data)); and ac.getItemAt(a).label)); both coming back 'undefined'

                   

                   

                  p.s. i get the same issue with the trace(str) method

                  • 6. Re: conditionals
                    Flex harUI Adobe Employee

                    It all depends on the data.  Try using ObjectUtil.toString() to dump the results.  It might make it easier to see what you need to do.

                     

                    Alex Harui

                    Flex SDK Developer

                    Adobe Systems Inc.

                    Blog: http://blogs.adobe.com/aharui

                    • 7. Re: conditionals
                      dmfsantacruz Level 1

                      Checked that out in livedocs and it seems like it is a lot more complicated than it needs to be. I havent seen any examples of using that with an ArrayCollection, so I am pretty much clueless on how to get the array data into an object to then  use that method.

                      I tried using the toString() method on my array collection directly and again only get [object Object][object Object] etc. etc. etc.

                       

                      Coming from an ASP and PHP background and using standard arrays quite often, this seems like a lot of unnecessary work.

                       

                      I have a feeling there may be something fundamentally wrong with the way the PHP script is generating the array.

                      If i try creating a standard array instead of an array collection and putting

                      omArray = event.result.response.data.row.source then use the omArray.toString() method I again get repeating object tags.

                       

                      Its odd because using omArray as a dataprovider for my datagrid works just fine, so the data is there and flex is seeing it, just not the way that I have tried to call it in the actionscript.

                      • 8. Re: conditionals
                        dmfsantacruz Level 1

                        finally got something to work with!!

                         

                        for (var i:uint = 0; i<omArray.length; i++) {

                        var omObject:Object

                        omObject = omArray.getItemAt(i);

                        trace(ObjectUtil.toString(omObject));

                        }

                         

                        I would still love to get this into a form that I can manipulate and do calculations on instead of a string.

                         

                        right now I have to break it up into individual records then split and split and split

                         

                        "bill_01 = 343"

                        "bill_05 = 542"

                        "bill_10 = 214"

                        etc etc

                         

                        I need to be able to manipulate these numbers individually and do calculations. If anyone has a clean solution I would be very appreciative!

                        • 9. Re: conditionals
                          Flex harUI Adobe Employee

                          Are you using AMFPHP?  At least you are getting objects.  You can then use registerClassAlias to try to have those objects become class instances.  Either way you can access properties from omObject like this:

                           

                          Var num:Number = omObject.bill_01;

                           

                          Alex Harui

                          Flex SDK Developer

                          Adobe Systems Inc.

                          Blog: http://blogs.adobe.com/aharui