5 Replies Latest reply on Dec 17, 2007 2:01 PM by systemsplanning

    Expecting colon before dot

      On this code:

      <mx:Repeater id="thumbnails" dataProvider="{myService.lastResult..thumbnail}">
      <mx.Image source="{thumbnails.currentItem}"
      rollOver="ShowFullImage({thumbnails.currentItem})" />

      the Flex compiler throws an error "expecting colon before dot". It doesn't like the {} inside the () in the call to ShowFullImage.

      {thumbnails.currentItem} is just a String -- a URL to an image. I know that part is correct, because if I replace the rollOver with ShowFullImage('dummy') it compiles OK and displays the thumbnails correctly.

      I've tried a dozen variations. And the syntax Function({...}) appears to be correct from googling. Any ideas would be much appreciated!

        • 1. Re: Expecting colon before dot
          ntsiii Level 3
          lastResult is an Object, and since you have strict (compile-time) error checking turned on, Flex does not understand that you are really working with an XML object. Plain Object does not have the decendant ".." operator, henct the compile time error.

          I advise declaring a typed (XMLListCOllection) instance variable to hold the dataProvider, and assigning it in a result handler, instead of using lastResult.

          Or, If you want to stay with binding, then try:

          • 2. Re: Expecting colon before dot
            ntsiii Level 3
            Never mind, I misread your post.

            First, you can't use binding braces in AS script, which is what your are doing by putting them inside the function call. this would be syntactically corect:

            However, it won't work because currentItem only exists when the repeated is rendering, and not when the tollOver event happens.

            You ned to use getRepeaterItem(), or better, create a custom component to repeat. It is much cleaner to code.
            • 3. Re: Expecting colon before dot
              systemsplanning Level 1
              Thanks! That would seem to be the right approach. Would you know of any sample code for a custom repeater that could jump-start me? Preferably one that parsed provider XML data, as I am trying to do. What I need to do is display a record's image and data when its thumbnail is rolled over.

              Many thanks for the help!

              • 4. Re: Expecting colon before dot
                ntsiii Level 3
                Here are some snippets, sorry that the forum will destroy the formatting.

                Goal: Display a list of items using a complex display for each item, and have each of those items behave like a menu element and respond to a click anywhere on the item by running a handler function.

                One solution is to use a Repeater with a custom component

                In the main app or component, declare the Repeater, and the click handler function.
                <mx:Application ...
                import MyRepeaterItem;

                private function onRPItemClick(oEvent:Event):void
                var xmlItem:XML = XML(oEvent.target);

                <mx:VBox ...>
                <mx:Repeater id="rp" dataProvider="{_xmlData}" ...>
                <!-- Note we pass in the entire currentItem, and define a click handler -->
                <MyRepeaterItem xmlItem="{rp.currentItem}" itemClick="onRPItemClick(event)" .../>

                And in the component, MyRepeaterItem.mxml:
                <?xml version="1.0" encoding="utf-8"?>
                <mx:HBox mouseChildren="false" buttonMode="true" click="onClick(event)" >
                <!-- The metadata tag below allows us to define an itemClick handler in mxml, as in the code above -->
                [Event(name="itemClick", type="flash.events.Event")]
                [Bindable]private var _xmlItem:XML;

                /** Setter function */
                public function set xmlItem(xml:XML):void
                _xmlItem = xml;
                //do any special, non-bound ui stuff you want
                }//set xmlItem

                /** Getter function */
                public function get xmlItem():XML
                return _xmlItem;
                }//get xmlItem

                /** Outer VBox Click handler function */
                private function onClick():void
                dispatchEvent(new Event("itemClick",false); //we do not need/want this event to bubble

                <!-- Now declare the Item UI -->
                <mx:Text id="lbDescription" text="{_xmlItem.@description}" width="100%" height="100%" />

                • 5. Re: Expecting colon before dot
                  systemsplanning Level 1
                  Thanks -- that looks like just what I need to get started!