How to run method from Class: Toybox::Graphics::Dc from within Behavior Delegate ?

Former Member
Former Member
How do I run the following code from the onKey function within my Behavior Delegate ?

dc.setColor(Gfx.COLOR_BLACK, Gfx.COLOR_BLACK);
dc.clear();
dc.setColor(Gfx.COLOR_WHITE, Gfx.COLOR_TRANSPARENT );

I get .. an error.

Could not find symbol dc.
Symbol Not Found Error

I did add .. using Toybox.Graphics as Gfx;
but it makes no difference.

I do not know anything about objects, methods or classes. :(

I can put a flag in there in put this code in onUpdate but I would prefer not to as it takes time for that to process, and this is time sensitive and I would rather have the code run upon the button being pressed immediately.
  • You don't have the dc in the delegate - it's passed as a parameter to onUpdate().

    You can go with your "set a flag in the delegate" approach (in a global). But what you probably missed, is after you set the flag, do a:

    Ui.requestUpdate()

    in the delegate.

    That will trigger a call to onUpdate() right away and you don't have to wait for the next "scheduled" call (based on a timer or something)
  • Former Member
    Former Member
    Ok .. thanks Jim, yes .. forgot about that. That will work nicely.

    Edit .. it is now perfect, a little tweak and no time lost.