Я новичок в Flex / Flash и пытаюсь создать простой музыкальный проигрыватель с кнопкой воспроизведения / паузы и HSlider, который показывает положение песни во время ее воспроизведения с использованием пользовательского класса SliderThumbClass. Я хотел бы позволить пользователю перетаскивать ползунок или нажимать на ползунок, чтобы изменить положение воспроизводимой в данный момент песни.
С кодом, который у меня есть ниже, если я использую sliderThumb, чтобы изменить положение воспроизводимой в данный момент песни, она прекрасно работает. Но если я щелкаю прямо по слайдерной дорожке, чтобы перейти вперед / назад, текущая позиция не перемещается, и происходит некоторое мигание текущей позиции, но она возвращается назад к тому месту, где она была, и продолжает воспроизведение песни. Это работает, если я нахожусь в состоянии паузы.
Как и ожидалось, события thumbDrag / Press / Release не запускаются, когда пользователь нажимает на sliderTrack - На какие события я должен подписаться для обработки этого случая?
Спасибо
<mx:Canvas>
<mx:Script>
<![CDATA[
...
...
private function onMusicPlay():void
{
...
this.addEventListener(Event.ENTER_FRAME,onEnterFrame);
...
}
private function onMusicPause():void
{
...
this.removeEventListener(Event.ENTER_FRAME,onEnterFrame);
...
}
//Invoked when the user changes the position of the slider using the thumb. It
// calculates the new position where the song should start playing.
private function onThumbDrag(event:Event):void
{
// if a song is loaded and we have the handles to it's sound and channel
// objects, allow the scrubber to drag and update state
if((_currentSong != null) && (_currentChannel != null))
{
_isDragging = true;
_currentSongLength = _currentSong.length;
_currentChannel.stop();
var playhead:Number = scrubSlider.value *.01;
_currentChannel = this.createChannel(_currentSong, (playhead * _currentSongLength));
}
}
//Calculates the time remaining on the current song
private function onEnterFrame(event:Event):void
{
// only calculate intervals if the user isn't dragging
// the length scrubber of the song, and if the song is playing
if(!_isDragging && !_isPaused)
{
scrubSlider.getThumbAt(0).x = ((_currentChannel.position / _currentSong.length) * scrubSlider.width);
var dtPosition : Date = new Date( _currentSong.length - _currentChannel.position);
_nSongPosition.text = _timeFormatter.format( dtPosition );
}
]]>
</mx:Script>
<mx:Image id="_pauseIcon" x="0" y="0" visible="true" click="pause()" source="@Embed('../icons/pause.png')"/>
<mx:Image id="_playIcon" x="0" y="0" visible="false" click="play(false)" source="@Embed('../icons/play.png')"/>
<mx:HSlider x="75" y="10" width="527" id="scrubSlider"
sliderThumbClass="components.LargeSliderThumb"
minimum="0" maximum="100"
liveDragging="true"
showDataTip="false"
thumbDrag="onThumbDrag(event)"
thumbPress="{_isDragging=true}"
thumbRelease="{_isDragging=false}"
thumbDownSkin="@Embed('../icons/sliderThumbIcon.png')"
thumbOverSkin="@Embed('../icons/sliderThumbIcon.png')"
thumbUpSkin="@Embed('../icons/sliderThumbIcon.png')"
trackSkin="@Embed('../icons/sliderTrack.png')" />
<mx:Text id="_nSongPosition" x="610" y="10" width="69" height="29" text="" color="#000000" fontWeight="bold" fontSize="18"/>
</mx:Canvas>