Having issues setting self variables with a Drawable class

I am having issues setting self variables with a Drawable class. I have a method to set the variables:

  function setInfo(numerator_ as Float, denominator_ as Float) as Void {
    self.numerator = numerator_;
    self.denominator = denominator_;
  }

In the draw method I am trying to address these variables as self.numerator and self.denominator. But when the draw method runs, these variables are empty. Does anyone know why? Thanks.

  • You might want to post more code, such as the code that calls setInfo() and the contents of your view's onUpdate() function. If you're calling View.onUpdate() in your view's onUpdate() function (and I assume you are), you would need to call setInfo() first, as View.onUpdate() renders all the Drawables in the app layout.

    You can also try adding System.println() calls to your code, so you can verify any assumptions about if and when your code is running. (i.e. is setInfo() really called before the drawable is drawn?)

  • I think it is because I have the class in the layout.xml and then I was initializing it and making it a global. And when the draw function was running it wasn't the instance that I was addressing.

    Is there a way to add a drawable instance to the layout during runtime?

  • Yeah, I figured it was something like that, but I didn't want to assume.

    Instead of trying to create your own instance of a drawable (which won't work if you also want to specify that drawable in an xml layout), use View.findDrawableById() to get a reference to the instance that was created in the layout. You can see examples of this in SDK samples such as PItchCounter.