A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Simple Counter problem

  1. #1
    Junior Member
    Join Date
    Dec 2009
    Posts
    15

    Simple Counter problem

    I am working on a game which needs a counter, and the counter code I found works fine, however I cannot see why at the very start instead of displaying a 0 the dynamic text box displays '_level0.counter'

    I'm quite new to flash still so I'm a tad confused ^_^

    heres the code:

    Code:
    var totalTime:Number = 0;
    timer = setInterval(addTime,1000);
    function addTime(){
    totalTime += 1;
    _root.counter = totalTime;
    }
    Any help would be awesome.

    Kind regards,

    Aravona

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Code:
    var totalTime:Number = 0;
    _root.counter = totalTime;
    timer = setInterval(addTime, 1000);
    function addTime() {
    	totalTime += 1;
    	_root.counter = totalTime;
    }

  3. #3
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    I only use the variable name in the textfield for debugging purposes. Best practice for Textfields (and Movieclips and Buttons) is to use an instance name. This can be done via the objects property panel.

    So, give your dynamic textfield an instance name. For example myCounter. Also, change totalTime - which is reserved - for myTime.

    Actionscript Code:
    var myTime:Number = 0;
    myCounter.text = myTime;

    timer = setInterval(addTime,1000);

    function addTime(){
    myTime += 1;
    myCounter.text = myTime;
    }

    gparis
    Last edited by gparis; 08-18-2010 at 09:22 AM. Reason: Good morning, dawsonk ;)

  4. #4
    Junior Member
    Join Date
    Dec 2009
    Posts
    15

    resolved

    Thanks both of you

    gparis your version works perfectly thank you

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center