A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: dispatchEvent timer

  1. #1
    Member
    Join Date
    Apr 2011
    Posts
    42

    dispatchEvent timer

    Hey all,

    Iv'e got a game with a stopwatch timer in it which stops when the game is complete.

    The game swf is loaded when a button is clicked in the main menu swf.

    I want to be able to take the time at the end of the game and dispatch an event so that once back at the main menu once the game is finished the time can be displayed.

    Any ideas if this can be done as the time will be different each time the game is played.

    EDIT: Forgot the include code I used for the timer.

    function TimerHandler(e:TimerEvent):void
    {
    var Seconds:String = String(uint(MyTimer.currentCount%60));
    var Minutes:String = String(uint((MyTimer.currentCount/60)%60))
    var Hours:String = String(uint((MyTimer.currentCount/60)/60));

    SecondText.text = (uint(Seconds)< 10) ? "0" + Seconds:Seconds;
    MinuteText.text = (uint(Minutes)< 10) ? "0" + Minutes:Minutes;
    HourText.text = (uint(Hours) < 10) ? "0" + Hours:Hours;
    }
    Last edited by AntBirch; 02-15-2012 at 04:23 PM.

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Why do you think you need an event for this? Just save it in a property and access it from the main menu.

  3. #3
    Member
    Join Date
    Apr 2011
    Posts
    42
    That's the only way I could think of doing this as not sure if I've created a property before. Is it straight forward to do?

  4. #4
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Yes, if you have a document class for you game swf, just declare a public variable in it. public variables on class instances are properties.

    If you do not have a document class, just assign a value dynamically.
    Code:
    this.totalTime = something;
    Then your main menu can access it by looking at the totalTime property of your game instance.
    Code:
    gameInstance.totalTime

  5. #5
    Member
    Join Date
    Apr 2011
    Posts
    42
    I've put this code in the continue button for the game.

    Code:
    this.totalTime = MyTimer;
    and then in the main menu I'm a little lost as I'm not sure what I put in the place of gameInstance? Am I linking to the games swf file?

  6. #6
    Member
    Join Date
    Apr 2011
    Posts
    42

    Mouse over

    Sorry please delete this.

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