Elevation Chart in Flex – using Timers

By Shahram Javey

Flex Route ChartIn my bike/hike route player application, I wish to have the usual controls to manage the speed of the playback, just like a DVD player controls. So that when you click on “start”, I wish to move the time line from left to right on the elevation chart and at the same time control the location of a marker on the map.

Yesterday, I tried to use Flex Effects so that when you click on the Start button the slider starts, and this in turn will move the time line (mapped as a Flex LineSeries). I couldn’t get this work, namely I couldn’t figure out how to update the time line. Today I came across the Timer object. I added an animate method that gets called when you click on the Start button (source code map.mxml)


		private function animate() : void {
			var timer : Timer = new Timer(elevationChartLength);
			timer.addEventListener("timer", onTimer);
			timer.start();
		}

		public function onTimer(event:TimerEvent) : void {
			var i : int = event.target.currentCount - 1;
			var v  : String = elevationData.getItemAt(i)["x"];
			sliderMove(v);
		}

This works, but it still not quite right (e.g., there is no easy way to control the speed of the animation, e.g.). So the search continues.

Here is how I was using Effects:


<mx:Sequence id="myMove" target="{slider}">
  <mx:AnimateProperty property="value"
        fromValue="{timeMin}"
        toValue="{timeMax}"
        duration="{selectedItem.data}"/>
</mx:Sequence>
<mx:Button id="controlSliderButton" x="10" y="253"
        label="Start" click="myMove.play();"/>

But I couldn’t figure out how during the animation of the slider, I could also update the time line.

Leave a Reply