14 Replies Latest reply on Jun 6, 2008 3:39 PM by cheftimo

    Problem with an itemRenderer

    cheftimo Level 2
      Hello, all:

      I posted about this before, with no results, but there is a lot more that can be seen now and maybe someone wants to look into it. From what I have seen in these forums recently, this may be something that Greg Lafrance or ntsiii might want to try to answer. Also, this may be a good subject for Peter Ent, but I haven't seen any posts by him lately – Peter, are you still with us?

      The application is a cartoon viewer, with which I want to replace one of the sections on my web site. I have to do a little more work on the help screen, but the rest is pretty much finished. The code is horrible, but I wanted to get this going.

      This is a bilingual application; it's here: http://www.timos.com/timos/greenEarth/greenEarth.html If I can figure out the problem I am having, I can eliminate two view states and have much cleaner code overall.

      The problem: I cannot get the 'Thumb' component (used here as an itemRenderer) to see a public variable called 'locale', created in the main application. I have declared this variable, (tried both public and private) in Thumb.mxml; I have tried creating the renderer inline; I have tried 'outerDocument.locale', but the thing won't even recognize that there is an outerDocument.

      View source is enabled, but for some reason, neither IE nor Firefox are showing the option in the context menu. However, you can browse to the source code: http://www.timos.com/timos/greenEarth/srcview/index.html.

      Just to give an idea of what I have in mind: all the captions for the cartoons are in a database that has a record for each cartoon – dimensions, imageName, etc. The different captions are in columns called 'caption_en_US' and 'caption_es_CO'. 'en_US' and 'es_CO' are the two locales used in the app, so somehow, it should be possible to do something like 'caption_{locale}' to get the appropriate caption to display. It works fine in the component that shows the original cartoon, and it would work in the itemRenderer if I could just get it to see that 'locale' variable.

      Looking forward to hearing a lot of good ideas about this. I will be watching this thread, so if anyone wants to know more, just ask. Best regards, to all,

      Carlos

        • 1. Re: Problem with an itemRenderer
          Gregory Lafrance Level 6
          I'm honored you mention my name! This works for me:
          ----------------- components/Thumb.mxml -------------
          <?xml version="1.0" encoding="utf-8"?>
          <mx:VBox xmlns:mx=" http://www.adobe.com/2006/mxml">
          <mx:Script>
          <![CDATA[
          import mx.core.Application;
          ]]>
          </mx:Script>
          <mx:Image source="images/france_agriculture.jpg" height="150" width="150"/>
          <mx:Text text="caption_{Application.application.locale}"/>
          </mx:VBox>
          ----------------- Test.mxml ----------------
          <?xml version="1.0"?>
          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" xmlns:comp="components.*">
          <mx:Script>
          <![CDATA[
          [Bindable]
          public var locale:String = "en_US";

          private function clickHandler():void{
          if(locale == "en_US"){
          locale = "es_CO";
          }
          else{
          locale = "en_US";
          }
          }
          ]]>
          </mx:Script>
          <comp:Thumb/>
          <mx:Button label="Change Locale" click="clickHandler()"/>
          <mx:Label id="lbl" text="{locale}"/>
          </mx:Application>
          • 2. Re: Problem with an itemRenderer
            cheftimo Level 2
            Greg, thanks very much for your help. I had not tried 'Application.application' because
            all the docs I have seen about itemRenderers say to use 'outerDocument'.

            So, now, my itemRenderer can see the variable, but for you or anyone else that wants to participate in this, when the 'locale' changes, this component is not picking up the change, even though all the proper variables are bindable.

            The other component that displays the full size cartoon is working the way I want – but that one is not a renderer, so it doesn't have to deal with the 'data' object.

            Maybe I have to write some kind of event listener.

            If anyone is interested in getting in the fray and wants me to post the nonworking project on my site, just speak and I shall comply.

            Thanks again, Greg.

            Carlos
            • 3. Re: Problem with an itemRenderer
              cheftimo Level 2
              OK, Greg et al –

              It looks like I was on the right track when I talked about en event listener im my previous post. I was looking ar a series of articles about itemRenderers in Peter Ent's blog and I found this:
              http://weblogs.macromedia.com/pent/archives/2008/03/itemrenderers_p_2.html.

              Frankly, this stuff is way advanced for me, so it will take me a while to figure it out. But my case should be simpler than the example in the above article.

              Locale change works everywhere in the app the way it's supposed to, except that the thumbnail captions do not get updated. This tells me that the TileList is not recreating its content (the itemRenderer) upon locale change. So, all I need is to know what code I might use to force a refresh of the TileList.
              when the locale chages.

              Also, I know that the function to update the caption in Thumb.mxml (the itemRenderer) works fine. If I pass to the function the actual name of the locale say, like this, buildDataCaption('es_CO') – not buildDataCaption(locale), it does what I expect.

              I have uploaded the project to http://www.timos.com/timos/greenEarthNEW/greenEarth.html and View Source is enabled, in case someone wants to take a stab at this.

              I would appreciate any ideas.

              Carlos

              • 4. Re: Problem with an itemRenderer
                Garyl Woolworth Level 1
                Did you resolve your issue? When I visit your example the captions seem to change fine for me when I switch between the languages unless maybe I'm missing something and not going to the right place.
                • 5. Re: Problem with an itemRenderer
                  Level 7
                  Did you resolve your issue? When I visit your example the captions seem to change fine for me when I switch between the languages unless maybe I'm missing something and not going to the right place.
                  • 6. Re: Problem with an itemRenderer
                    cheftimo Level 2
                    Hello, Kaotic101:

                    I caused some confusion the way I wrote my initial post. I meant to explain that the sample on the URL I gave there does work correctly. Please look at the fourth post on this thread, where the URL for the non-working app is. The first one is the way it SHOULD work, except that the code is very bad.

                    So, here is, again, the URL for the one where I am having the problem: http://www.timos.com/timos/greenEarthNEW/greenEarth.html. View Source is enabled. Sorry about the confusion.

                    Any ideas from anyone would be greatly appreciated.

                    Carlos
                    • 7. Re: Problem with an itemRenderer
                      Garyl Woolworth Level 1
                      Hey instead of trying to have all the renderer's listen for one value on the Application.application why not set a value inside of the array collection that they all can read and listen to internally? Essentially the idea is whenever you get a new ResultEvent back or the locale changes based on user selection you need to update carton .locale to the new locale. Then all of your renderers will be able to see this via data.locale. You could then override the data setter method to have it update the caption with the new value. I've also attached some code to explain what I'm getting at.
                      • 8. Re: Problem with an itemRenderer
                        VarioPegged Level 2
                        I do like what Kaotic is suggesting, but here's another approach for your consideration using events. This is a quick and semi-dirty approach, but should also give you what you're looking for.

                        TS
                        • 9. Problem with an itemRenderer
                          cheftimo Level 2
                          A happy ending???

                          Thanks to the help in these forums, I am getting there. I have been fooling around with ColdFusion for years, but this ActionScript thing might as well be Sanscript. I am still having a hell of a time understanding events.

                          I am ignorant, but I think my instincts are working OK. Before I started this thread just three days ago, I thought that if I could have the right 'data' object for the itemRenderer, all the problems would be taken care of. I had tried this: (see the attached code).

                          Of course, since the 'i' was in the wrong place, the compiler was ******** to no end and the complaints looked like Sanscript too.

                          Upon reading the previous two replies earlier, I put the above loop in a function called 'setCaptionInAC()', this time with the 'i' where it belongs, and voilá, it all works! I call this function in the resultHandler for 'svc' (the RemoteObject) and in the localeList_ChangeHandler().

                          You don't know how great it was to see the 'cartoons' AC with its new oolumn in the debugger. And now, my 'Thumb' itemRenderer has just these 2 lines of code within the VBox root tag:

                          <mx:Image source="../assets/images/cartoons/thumbs/{data.imageName}_150.jpg" height="150" width="150"/>
                          <mx:Text text="{data.caption}" textAlign="center" width="140" fontWeight="bold" fontSize="12" color="#000000"/>

                          Now, I just have one concern: this seems too easy, like it's too good to be true. Is any of this stuff I did a bad practice? If anyone has a comment, I would like to hear it.

                          So, Kaotic101, thank you for teaching me how to loop through an ArrayCollection properly. And thank you, VarioPegged, you made me aware of a couple of things about events, a subject I know I have to do a lot of work on.

                          Carlos
                          • 10. Re: Problem with an itemRenderer
                            Garyl Woolworth Level 1
                            No problem, I wouldn't say any of it is really bad practice. If you look at it this way it's a pretty tough to argue when you can accomplish the same goal with 4 lines of code through an ArrayCollection binding compared to 20 lines of procedure code trying to force a reset of dataProviders and update display lists.
                            • 11. Re: Problem with an itemRenderer
                              VarioPegged Level 2
                              Hey, easy is good ;-)

                              What you're doing is definitely the preferred way of doing it ... meaning a no-nonsense itemRenderer. Manipulating the data provider in your case is fine, users are only likely to choose between English and Spanish once or maybe twoce, so looping through the AC won't be a problem. However, in a case where there may be thousands of items and you can expect users to constantly flip between this setting and that setting that rely on that dp, you may see a performance hit using that approach. These solutions you assess on a case-by-case basis.

                              As far as events are concerned, it's a good thing. Learn to use events properly, and you shall elevate your whole life's meaning to a level hitherto only imagined :-)

                              TS
                              • 12. Re: Problem with an itemRenderer
                                cheftimo Level 2
                                OK, after getting Kaotic101's and VarioPegged's blessing of my newbie code, I have moved things around in my remote server. Just in case anyone wants to refer to it, the revised project is here: http://www.timos.com/timos/greenEarth/greenEarth.html; View Source is no longer enabled.

                                Thanks again to the above and to Greg Lafrance for the help. I'm sure I'll be back soon.

                                Best to all,

                                Carlos
                                • 13. Re: Problem with an itemRenderer
                                  VarioPegged Level 2
                                  Works great.

                                  Don't know if you know about this, but in the cartoon detail view (after you've highlighted a thumbnail icon and selected "See selected cartoons") you have an issue with the vertical scroll bar of the thumbnails on the right. If the browser window is vertically resized smaller than the cartoon detail, then that panel's scroll bar is what is shown, not the thumbnails' scroll bar. One scroll bar is on top of the other. I can't say for certain how to rectify this because you don't have the source up anymore.

                                  TS
                                  • 14. Re: Problem with an itemRenderer
                                    cheftimo Level 2
                                    Hi TS. I had the tile list constrained to be 0 pixels from the right side. I changed that: now you can see both scroll bars and there is even a little gap between them so it’s really clear that there are two of them.

                                    Thanks for pointing this out, and if you see any more gaffes, please whip my a--.

                                    Carlos