1 Reply Latest reply: May 31, 2007 2:40 PM by robs72 RSS

    Passing Repeater dataProvider info to an AS function showing 1067 error

    robs72 Community Member
      Hi,
      I'm getting a compiler error 1067: Implicit coercion of a value of type String to an unrelated type Number, with this following code (against the lines x="getRelXPos({wallRepeater.currentItem.x});" and y="getRelYPos({wallRepeater.currentItem.y});"), I haven't a clue what it means though.

      The data wallAC comes in from an external XML file with a bunch of thumb nodes, x and y values are 0.0 to 1.0 so I can make up a relative coordinate system regardless of window size.


      MXML:
      <mx:Repeater id="wallRepeater" dataProvider="{wallAC.thumb}">
      <mx:VBox
      width="100"
      height="120"
      x="getRelXPos({wallRepeater.currentItem.x});"
      y="getRelYPos({wallRepeater.currentItem.y});">
      </mx:VBox>
      </mx:Repeater>

      AS:
      public function getRelXPos(xVal:Number):Number {
      var iW:Number = myCanvas.width;
      var xPos:Number = xVal * iW;
      return xPos;
      }

      public function getRelYPos(yVal:Number):Number {
      var iH:Number = myCanvas.height;
      var yPos:Number = yVal * iH;
      return yPos;
      }

      My first guess was that Flex was treating the wallRepeater.currentItem.x and y values as strings and so was expecting a string back, so I changed the functions to look like this:

      public function getRelXPos(xVal:String):String {
      var iW:Number = myCanvas.width;
      var xPos:Number = parseFloat(xVal) * iW;
      return xPos.toString();
      }

      But that still showed the same compiler error.

      Any ideas on where I'm going wrong here? I should point out that I'm pretty rubbish at Actionscript!

      Cheers,
      Rob
        • 1. Re: Passing Repeater dataProvider info to an AS function showing 1067 error
          robs72 Community Member
          woohoo!! I seem to be getting good at answering my own questions:

          x="{getRelXPos(wallRepeater.currentItem.x)}"
          y="{getRelYPos(wallRepeater.currentItem.y)}"

          public function getRelXPos(xVal:String):Number {
          var iW:Number = myCanvas.width;
          var xPos:Number = parseFloat(xVal) * iW;
          return xPos;
          }

          public function getRelYPos(yVal:String):Number {
          var iH:Number = myCanvas.height;
          var yPos:Number = parseFloat(yVal) * iH;
          return yPos;
          }

          Is it a string, is it a number, who knows?!! At least it works ;)