его код
Код:
package
{
import flash.display.*;
import flash.net.*;
import flash.events.*;
import flash.text.*;
import flash.utils.*;
import flash.media.*;
import flash.ui.*;
import fl.controls.*;
import fl.data.*;
import fl.events.*;
public class player extends MovieClip
{
// url prefix
//var urlPrefix:String = "http://localhost/eurasia/audio/";
//var urlPrefix:String = "http://temp.pertsev.com/eurasia/audio/";
var urlPrefix:String = "http://webtest.softdeco.net/eurasia/audio/";
//var urlPrefix:String = "../";
// all player data
var dataXML:XML = null;
// compositions list related
var compoListOpened:Boolean = true;
var compoListCloseInterval, compoListOpenInterval:Number = 0;
// current radio type
var radioType:String = "Тарантайка дэйли";
// sound related things
var soundObject:Sound = new Sound();
var soundChannel:SoundChannel = null;
var soundTrans:SoundTransform = new SoundTransform();
// update interval
var soundUpdateInterval:Number = 0;
// information about sound
var soundLengthRaw:String = "";
var soundLengthSecs:Number = 0;
var soundIsPlaying:Boolean = false;
var soundIsPaused:Boolean = false;
var soundPausePosition:Number = 0;
// images for sound
var images:Array = new Array();
var imageCurrentIndex:Number = 0;
var hasImages:Boolean = false;
var volumeDrag:Boolean = false;
// helper arrays
var arrayRadio1:Array = new Array();
var arrayRadio2:Array = new Array();
var currentTrack:Object = null;
var firstRun:Boolean = true;
// default constructor
public function player()
{
prepareData();
prepareTestingFeatures();
prepareContextMenu();
prepareButtons();
prepareCompoList();
prepareTrackBar();
prepareVolumeSlider();
}
protected function prepareTestingFeatures():void
{
}
protected function prepareContextMenu():void
{
function item1MenuItemSelectHandler(event:ContextMenuEvent):void
{
var urlRequest:URLRequest = new URLRequest("http://pertsev.com");
navigateToURL(urlRequest);
}
//function item2MenuItemSelectHandler(event:ContextMenuEvent):void
//{
//var urlRequest:URLRequest = new URLRequest("http://pertsev.com");
//navigateToURL(urlRequest);
//}
var item1:ContextMenuItem = new ContextMenuItem("a`pertsev design — студия дизайна Александра Перцева");
//var item2:ContextMenuItem = new ContextMenuItem("Код: resurtm (e-mail: resurtm@gmail.com)");
item1.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, item1MenuItemSelectHandler);
//item2.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, item2MenuItemSelectHandler);
var contMenu:ContextMenu = new ContextMenu();
contMenu.customItems.push(item1);
//contMenu.customItems.push(item2);
contMenu.hideBuiltInItems();
this.contextMenu = contMenu;
}
// prepare all buttons in gui
protected function prepareButtons():void
{
// play and stop buttons
playButton.visible = true;
stopButton.visible = false;
function playButtonClickHandler(event:MouseEvent):void
{
if (!soundIsPlaying)
{
if (!soundIsPaused)
soundChannel = soundObject.play(0, 0, soundTrans);
else
{
soundChannel = soundObject.play(soundPausePosition, 0, soundTrans);
soundIsPaused = false;
}
soundChannel.addEventListener(Event.SOUND_COMPLETE, soundChannelSoundCompleteHandler);
soundIsPlaying = true;
}
}
function stopButtonClickHandler(event:MouseEvent):void
{
if (soundIsPlaying)
{
soundPausePosition = soundChannel.position;
soundChannel.stop();
soundIsPlaying = false;
soundIsPaused = true;
}
}
playButton.addEventListener(MouseEvent.CLICK, playButtonClickHandler);
stopButton.addEventListener(MouseEvent.CLICK, stopButtonClickHandler);
// radio tabs
function radioTab1ClickHandler(event:MouseEvent):void
{
compoList.radioTab1.gotoAndStop(1);
compoList.radioTab2.gotoAndStop(2);
radioType = "Тарантайка дэйли";
updateData();
}
function radioTab2ClickHandler(event:MouseEvent):void
{
compoList.radioTab1.gotoAndStop(2);
compoList.radioTab2.gotoAndStop(1);
radioType = "Две жизни спустя";
updateData();
}
compoList.radioTab1.addEventListener(MouseEvent.CLICK, radioTab1ClickHandler);
compoList.radioTab2.addEventListener(MouseEvent.CLICK, radioTab2ClickHandler);
compoList.radioTab1.gotoAndStop(1);
compoList.radioTab2.gotoAndStop(2);
// close button
function compoListCloseIntervalHandler():void
{
compoList.x += (405.0 - compoList.x) * 0.2;
if (compoList.x > 400.0)
clearInterval(compoListCloseInterval);
}
function compoListOpenIntervalHandler():void
{
compoList.x += (136.7 - compoList.x) * 0.2;
if (compoList.x < 141.7)
clearInterval(compoListOpenInterval);
}
function closeButtonClickHandler(event:MouseEvent):void
{
if (compoListOpened)
{
compoList.closeArrow.rotation = 180;
compoListOpened = false;
compoListCloseInterval = setInterval(compoListCloseIntervalHandler, 50);
}
else
{
compoList.closeArrow.rotation = 0;
compoListOpened = true;
compoListOpenInterval = setInterval(compoListOpenIntervalHandler, 50);
}
}
compoList.closeButton.addEventListener(MouseEvent.CLICK, closeButtonClickHandler);
// next and prev buttons
function prevButtonClickHandler(event:MouseEvent):void
{
if (event.stageX < 314.6 || event.stageX > 346.6 ||
event.stageY < 118.4 || event.stageY > 150.8)
return;
if (currentTrack == null)
return;
//trace("test1");
var gotoIndex:Number = -1;
if (radioType == "Тарантайка дэйли")
{
for (var i:Number = 0; i < arrayRadio1.length; i++)
if (arrayRadio1[i].name == currentTrack.name &&
arrayRadio1[i].comment == currentTrack.comment)
gotoIndex = i - 1;
if (gotoIndex != -1 && gotoIndex != arrayRadio1.length)
{
listItemClickHandler(new ListEvent("itemClick", false, false, -1, -1, -1, arrayRadio1[gotoIndex]));
compoList.list.scrollToIndex(gotoIndex);
}
}
if (radioType == "Две жизни спустя")
{
for (var i:Number = 0; i < arrayRadio2.length; i++)
if (arrayRadio2[i].name == currentTrack.name &&
arrayRadio2[i].comment == currentTrack.comment)
gotoIndex = i - 1;
if (gotoIndex != -1 && gotoIndex != arrayRadio2.length)
{
listItemClickHandler(new ListEvent("itemClick", false, false, -1, -1, -1, arrayRadio2[gotoIndex]));
compoList.list.scrollToIndex(gotoIndex);
}
}
}
function nextButtonClickHandler(event:MouseEvent):void
{
if (currentTrack == null)
return;
if (event.stageX < 601.4 || event.stageX > 634.2 ||
event.stageY < 118.4 || event.stageY > 150.8)
return;
//trace("test2");
var gotoIndex:Number = -1;
if (radioType == "Тарантайка дэйли")
{
for (var i:Number = 0; i < arrayRadio1.length; i++)
if (arrayRadio1[i].name == currentTrack.name &&
arrayRadio1[i].comment == currentTrack.comment)
gotoIndex = i + 1;
if (gotoIndex != -1 && gotoIndex != arrayRadio1.length)
{
listItemClickHandler(new ListEvent("itemClick", false, false, -1, -1, -1, arrayRadio1[gotoIndex]));
compoList.list.scrollToIndex(gotoIndex);
}
}
if (radioType == "Две жизни спустя")
{
for (var i:Number = 0; i < arrayRadio2.length; i++)
if (arrayRadio2[i].name == currentTrack.name &&
arrayRadio2[i].comment == currentTrack.comment)
gotoIndex = i + 1;
if (gotoIndex != -1 && gotoIndex != arrayRadio2.length)
{
listItemClickHandler(new ListEvent("itemClick", false, false, -1, -1, -1, arrayRadio2[gotoIndex]));
compoList.list.scrollToIndex(gotoIndex);
}
}
}
prevButtonZone.addEventListener(MouseEvent.CLICK, prevButtonClickHandler);
nextButtonZone.addEventListener(MouseEvent.CLICK, nextButtonClickHandler);
prevButton.visible = false;
nextButton.visible = false;
prevButtonZone.addEventListener(MouseEvent.ROLL_OVER, function() { prevButton.visible = true; } );
prevButtonZone.addEventListener(MouseEvent.ROLL_OUT, function() { prevButton.visible = false; } );
nextButtonZone.addEventListener(MouseEvent.ROLL_OVER, function() { nextButton.visible = true; } );
nextButtonZone.addEventListener(MouseEvent.ROLL_OUT, function() { nextButton.visible = false; } );
}
// prepare compositions list
protected function prepareCompoList():void
{
//var myCalibri:Font = new MyCalibri();
var textFormat:TextFormat = new TextFormat();
//textFormat.font = "Calibri";
//textFormat.font = myCalibri.fontName;
textFormat.size = 10;
textFormat.color = 0xFFFFFF;
compoList.list.setRendererStyle("disabledTextFormat", textFormat);
compoList.list.setRendererStyle("textFormat", textFormat);
compoList.list.setRendererStyle("embedFonts", false);
compoList.list.addEventListener(ListEvent.ITEM_CLICK, listItemClickHandler);
}
function listItemClickHandler(event:ListEvent):void
{
soundLengthRaw = String(event.item.length_raw);
soundLengthSecs = Number(event.item.length_secs);
if (soundIsPlaying)
{
soundChannel.stop();
soundIsPlaying = false;
}
if (soundObject.bytesTotal != soundObject.bytesLoaded)
soundObject.close();
soundObject = null;
soundObject = new Sound();
soundObject.load(new URLRequest(urlPrefix + "data/" + event.item.audio), new SoundLoaderContext(2000));
soundChannel = soundObject.play(0, 0, soundTrans);
//soundChannel.stop();
|