3 Replies Latest reply on Jun 12, 2007 1:39 PM by SemperSalvus

    Package/Class/Function Problem

      From the Getting Started Lessons in Flex Builder 2, one thing I am trying to learn (but failing) is how to use the TimerEvent class. The sample uses the following code:

      import flash.display.Sprite;
      import flash.events.TimerEvent
      import flash.utils.Timer

      public class ShortTimer extends Sprite
      public function ShortTimer()
      // creates a new five-second Timer
      var minuteTimer:Timer = new Timer(1000, 5);

      // designates listeners for the interval and completion events
      minuteTimer.addEventListener(TimerEvent.TIMER, onTick);
      minuteTimer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);

      // starts the timer ticking

      public function onTick(evt:TimerEvent):void
      // displays the tick count so far
      // The target of this event is the Timer instance itself.
      trace("tick " + evt.target.currentCount);

      public function onTimerComplete(evt:TimerEvent):void
      trace("Time's Up!");

      I cannot get this code to work any way I try it. If I put the code in an mxml app it gives back an error that a package cannot be nested. If I put the code in its own component file, I cannot get anything (like a button) to call the ShortTimer function to run the Timer.

      I tried the following code in an mxml app to call the function that is in the component file and I named the package Whatever and put the component in a folder named Whatever within the project.

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">

      import Whatever.ShortTimer;

      <mx:Panel height="100%" width="100%">
      <mx:Button id="PushMe" label="Push Me!" click="Whatever.ShortTimer;"/>


      If I click the button in debug mode, nothing happens. I would have thought the above eventlistener in the click event would need to have open and close parens after it, but if I put them in there it comes back with an error about not having enough arguments (why would the ShortTimer function need an argument anyway?).

      Can anyone please help me? I am sure I am missing out on some simple syntax or Flex Builder 2 setup that I have yet to understand.