5 Replies Latest reply on Oct 14, 2008 4:57 PM by Newsgroup_User

    Possible to have Function to return Flex Code (ie: <mx:Text text="hello world"/>)???

    Cole_62
      I'm new to Flex and need to special case some functionality using XML...not all feed items come with images so I thought the best way to handle this was to pass each feed item to a function that can use if statements and then return the appropriate code back to the user interface:

      For example printFeed() would would return something like the following if there were an image:

      <mx:Text text="{XML.channel.currentItem.title}"/>
      <mx:Image source="{XML.channel.currentItem.img.url}"/>

      OR the following if there were NOT an image:
      <mx:Text text="{XML.channel.currentItem.title}"/>

      Is this the correct approach? Also, what is the correct way to invoke printFeed? {printFeed("..."))} throws parsing errors.

      THANK YOU!

      -Cole
        • 1. Re: Possible to have Function to return Flex Code (ie: &lt;mx:Text text=&quot;hello world&quot;/&gt;)???
          atta707 Level 2
          No. I don't think this is the way to go!

          How about on application start up you call something like:

          setupPrintFeed() {
          var text:Text = new Text();
          text.title = ....;

          this.addChild(text);

          var image:Image;

          if (showImage) {
          image = new Image();
          image.source =.....
          this.addChild(image)
          }

          Of course, you can decide which container you wanna add your newly created controls.

          Is this what you're looking for?

          ATTA


          }
          • 2. Re: Possible to have Function to return Flex Code (ie: &lt;mx:Text text=&quot;hello world&quot;/&gt;)???
            Cole_62 Level 1
            no i dont think this will work because i need to iterate through each <item> in the XML...below is an exmaple of possible tree structure of the XML:
            channel
            -->item1
            ----->title
            ----->imgs
            --------->imgUrl
            --------->imgUrl
            -->item2
            ----->title
            ----->imgs
            ---------->imgUrl
            -->item3
            ------>title
            ------>imgs
            ----------->(no imgs)

            i thought to handle this using something like the ATTACHED CODE below:

            ...i need to be able to go through each <item> and <imgUrl> (because i dont know how many (if any) there are!) sorry if my PHP background shines through!

            THANKS!
            • 3. Re: Possible to have Function to return Flex Code (ie: &lt;mx:Text text=&quot;hello world&quot;/&gt;)???
              Level 7

              "Cole_62" <webforumsuser@macromedia.com> wrote in message
              news:gd2q5r$f08$1@forums.macromedia.com...
              > no i dont think this will work because i need to iterate through each
              > <item> in
              > the XML...below is an exmaple of possible tree structure of the XML:
              > channel
              > -->item1
              > ----->title
              > ----->imgs
              > --------->imgUrl
              > --------->imgUrl
              > -->item2
              > ----->title
              > ----->imgs
              > ---------->imgUrl
              > -->item3
              > ------>title
              > ------>imgs
              > ----------->(no imgs)
              >
              > i thought to handle this using something like the ATTACHED CODE below:
              >
              > ...i need to be able to go through each <item> and <imgUrl> (because i
              > dont
              > know how many (if any) there are!) sorry if my PHP background shines
              > through!
              >
              > THANKS!
              >
              > <mx:Repeater id="feed" dataProvider="{XML.channel.item}">
              > <mx:HBox>
              > <mx:Text text="{feed.currentItem.title}"/>
              > <mx:Repeater id="item" dataProvider="{feed.currentItem.imgs}">
              > <!-- PSEUDO CODE I NEED HELP RESOLVING:
              > if ("{item.currentItem.imgURL}")
              > -->
              > <mx:Image source="{item.currentItem.imgUrl}"/>
              > </mx:Repeater>
              > </mx:HBox>
              > </mx:Repeater>

              How bout

              <mx:Repeater id="feed" dataProvider="{XML.channel.item}">
              <mx:HBox>
              <mx:Text text="{feed.currentItem.title}"/>
              <mx:Repeater id="item" dataProvider="{feed.currentItem.imgs}">
              <mx:Image
              source="{item.currentItem.imgURL.length()>0?item.currentItem.imgURL:null}"
              includeInLayout="{item.currentItem.imgURL.length()>0}"/>
              </mx:Repeater>
              </mx:HBox>
              </mx:Repeater>



              • 4. Re: Possible to have Function to return Flex Code (ie: &lt;mx:Text text=&quot;hello world&quot;/&gt;)???
                Cole_62 Level 1
                Thank you Amy! While your answer was not quite the solution, it informed me of the visible and includeInLayout options...I created a function that tests if the length is >0 and returns true/false which is fed into visible and includeInLayout
                • 5. Re: Possible to have Function to return Flex Code (ie: &lt;mx:Text text=&quot;hello world&quot;/&gt;)???
                  Level 7

                  "Cole_62" <webforumsuser@macromedia.com> wrote in message
                  news:gd3bap$5ak$1@forums.macromedia.com...
                  > Thank you Amy! While your answer was not quite the solution, it informed
                  > me of
                  > the visible and includeInLayout options...I created a function that tests
                  > if
                  > the length is >0 and returns true/false which is fed into visible and
                  > includeInLayout

                  Glad I could help