0

reference to myView.Myfunc from setTimeout

How do I call myFunction from within myView using setTimeout ?

I've tried

var myTimer = KONtx.utility.timer.setTimeout("KONtx.myView.myFunction();", 1000);
var myTimer = KONtx.utility.timer.setTimeout("KONtx.views.myView.myFunction();", 1000);
var myTimer = KONtx.utility.timer.setTimeout("KONtx.application.myView.myFunction();", 1000);
var myTimer = KONtx.utility.timer.setTimeout("myView.myFunction();", 1000);

I'm guessing this is the wrong approach smile.gif
Do I need to setup and dispatch custom events instead ? Or is there a valid reference I can use from the global scope ?

5 Replies
  • QUOTE (lee.bettridge @ May 7 2009, 02:04 AM) <{POST_SNAPBACK}>
    How do I call myFunction from within myView using setTimeout ?

    I've tried

    var myTimer = KONtx.utility.timer.setTimeout("KONtx.myView.myFunction();", 1000);
    var myTimer = KONtx.utility.timer.setTimeout("KONtx.views.myView.myFunction();", 1000);
    var myTimer = KONtx.utility.timer.setTimeout("KONtx.application.myView.myFunction();", 1000);
    var myTimer = KONtx.utility.timer.setTimeout("myView.myFunction();", 1000);

    I'm guessing this is the wrong approach :)-Jeremy
    0
  • Your correct in that I am creating the timer from inside a method in the view class. I'm trying to do some very (very) basic animation, so moving a container that holds an image in small increments across the screen by recursively calling a function say, once every half second using a timer.

    I would normally have some sort of closeWindow / closeView function that cancels timers and does other general clean up code, so would be nice to know how to implement that in a widget.
    0
  • QUOTE (lee.bettridge @ May 8 2009, 07:49 AM) <{POST_SNAPBACK}>
    Your correct in that I am creating the timer from inside a method in the view class. I'm trying to do some very (very) basic animation, so moving a container that holds an image in small increments across the screen by recursively calling a function say, once every half second using a timer.

    I would normally have some sort of closeWindow / closeView function that cancels timers and does other general clean up code, so would be nice to know how to implement that in a widget.


    Glad I asked. Instead of using a timer, you would probably have better luck using the built in animation functions inside the engine. An example:

    CODE
    var move = new MoveAnimation(objToMove, toX, toY, duration, easeType);
    animator.start(move);
    // (if you have a variable named this.foo which points to the container, then objToMove should be: this.foo.element)
    // (duration is specified in milliseconds here)
    // (easeType is from constants stored as: animator.kEaseIn, animator.kEaseOut, animator.kEaseInOut, animator.kEaseNone )


    More animation documentation can be found in the Konfabulator manual at http://manual.widgets.yahoo.com

    If all you are doing is a simple animation like you described, that should "probably" work on TVs. The TVs don't have anywhere near the processing power the simulator does running on your desktop, so please try and be cognizant of that.

    Also, to answer the last part of your question, all view classes have a hideView method which you can define which will be called when your view is hidden. There is also a destroyView method which you can use when your view is being garbage collected, but that's usually of less utility than hideView.

    -Jeremy
    0
  • Thanks for the advice.

    I didn't know widgets had 'Actionscript' style tween anims :)My plan is to try out a very simple maze game so I can get a benchmark on animation capability.
    0
  • QUOTE (lee.bettridge @ May 8 2009, 01:13 PM) <{POST_SNAPBACK}>
    Thanks for the advice.

    I didn't know widgets had 'Actionscript' style tween anims :)-Jeremy
    0

Recent Posts

in General - Yahoo! TV Widgets