Código :
stop();
Stage.scaleMode="noScale";
txtPlayTime.text = "00:00 / 00:00";
tooltip.txtTitle.text = "";
tooltip.txtDesc.text = "";
tooltip._alpha = 0;
nowplaying.txtNowPlaying.text = "";
nowplayingicon._alpha = 0;
nowplaying._alpha = 0;
bufferClip._visible = false;
//var buffersm = 5;
//var buffermd = 6;
//var bufferlg = 8;
//var bufferhd = 10;
var home:MovieClip = this;
var centerX:Number = Stage.width/2;
var centerY:Number = Stage.height/2;
var startPosition:Number = loaderbar._x;
//Load the poll config file
var xmlFlvPinfo = new XML();
xmlFlvPinfo.ignoreWhite = true;
xmlFlvPinfo.onLoad = function(success)
{
if (success)
{
var configFile = this.firstChild.childNodes[0].attributes.pollsettingsfile;
setFlvPsettings(configFile);
}
}
xmlFlvPinfo.load("cafaFLVPlayerUID.xml");
function setFlvPsettings(configFile, pollUId)
{
var xmlFlvPsettings = new XML();
xmlFlvPsettings.ignoreWhite = true;
xmlFlvPsettings.onLoad = function(success)
{
if (success)
{
var _bgcolor = this.firstChild.childNodes[0].attributes.bgcolor;
var _tooltipbgcolor = this.firstChild.childNodes[0].attributes.tooltipbgcolor;
var _tooltiptext1color = this.firstChild.childNodes[0].attributes.tooltiptext1color;
var _tooltiptext2color = this.firstChild.childNodes[0].attributes.tooltiptext2color;
_global._tooltipbgalpha = this.firstChild.childNodes[0].attributes.tooltipbgalpha;
var _nowplayingbgcolor = this.firstChild.childNodes[0].attributes.nowplayingbgcolor;
var _nowplayingtextcolor = this.firstChild.childNodes[0].attributes.nowplayingtextcolor;
_global._nowplayingbgalpha = this.firstChild.childNodes[0].attributes.nowplayingbgalpha;
setBGnBD(1, _bgcolor);
var oFormat:TextFormat = new TextFormat();
oFormat.color = _tooltiptext1color;
tooltip.txtTitle.setNewTextFormat(oFormat);
var oFormat:TextFormat = new TextFormat();
oFormat.color = _tooltiptext2color;
tooltip.txtDesc.setNewTextFormat(oFormat);
var oFormat:TextFormat = new TextFormat();
oFormat.color = _nowplayingtextcolor;
nowplaying.txtNowPlaying.setNewTextFormat(oFormat);
//Now Playing BG Color
setBGnBD(2, _nowplayingbgcolor);
//Tooltip BG Color
setBGnBD(3, _tooltipbgcolor);
}
}
xmlFlvPsettings.load(configFile);
}
//Set the video connection
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream (nc);
//Set the buffer time in seconds
ns.setBufferTime(5);
var duration:Number;
ns["onMetaData"] = function(obj) {
duration = obj.duration;
}
//var1, var2 and var3 - Testing Labels - Safe to remove
//var1.html = true;
//var2.html = true;
//var3.html = true;
var buffer_interval:Number = setInterval(checkBufferTime, 100, ns);
function checkBufferTime(my_ns:NetStream):Void
{
var bufferPct:Number = Math.min(Math.round(my_ns.bufferLength/my_ns.bufferTime*100), 100);
//Variables xx1, xx2 and xx3 - For testing purposes - Safe to remove
//How much is in the buffer
var xx1 = "Length: "+Math.round(my_ns.bufferLength);
//What is the total buffer amount
var xx2 = "Time: "+my_ns.bufferTime;
//The percentage loaded in the buffer
var xx3 = "Buffer: "+bufferPct;
//Playing Time
var ns_seconds:Number = my_ns.time;
var minutes:Number = Math.floor(ns_seconds/60);
var seconds = Math.floor(ns_seconds%60);
if (seconds<10) {
seconds = "0"+seconds;
}
var ctime = minutes+":"+seconds;
//Total Time
var tns_seconds:Number = duration;
var tminutes:Number = Math.floor(tns_seconds/60);
var tseconds = Math.floor(tns_seconds%60);
if (tseconds<10) {
tseconds = "0"+tseconds;
}
var ttime = tminutes+":"+tseconds;
if(ttime == "NaN:NaN")
{
ttime = "00:00";
}
//Labels var1, var2 and var3 - For testing purposes - safe to remove
//var1.htmlText = xx1;
//var2.htmlText = xx2;
//var3.htmlText = xx3;
txtPlayTime.text = ctime + " / " + ttime;
if(Math.round(my_ns.bufferLength) == 5)
{
bufferClip._visible = false;
}
}
/*
ns.onStatus = function(info)
{
if(info.code == "NetStream.Buffer.Full")
{
bufferClip._visible = false;
}
if(info.code == "NetStream.Buffer.Empty")
{
bufferClip._visible = true;
}
//Plays the movie on a loop
if(info.code == "NetStream.Play.Stop")
{
bufferClip._visible = false;
ns.seek(0);
}
}
*/
//Set the film strip
var startPos:Number = -5.5;
var Increment:Number = 22;
var mxNumMovies:Number = Math.round(Stage.width / 22) + 1;
for(count=1;count<mxNumMovies;count++)
{
var posX:Number = -startPos + (count * Increment);
filmwhitehole1.duplicateMovieClip("filmwhitehole"+count, this.getNextHighestDepth(), {_x:posX, _y:filmwhitehole1._y});
filmwhitehole2.duplicateMovieClip("filmwhitehole"+count*mxNumMovies, this.getNextHighestDepth(), {_x:posX, _y:filmwhitehole2._y});
}
rewindButton.onRelease = function ()
{
ns.seek (0);
};
playButton.onRelease = function ()
{
ns.pause ();
};
btnFullScreen.onRelease = function ()
{
toggleFullScreen();
};
var videoInterval = setInterval(videoStatus, 100);
var amountLoaded:Number;
function videoStatus() {
amountLoaded = ns.bytesLoaded / ns.bytesTotal;
loaderbar.loadbar._width = amountLoaded * 220;
loaderbar.scrub._x = ns.time / duration * 220;
}
var scrubInterval;
//Scrub icon
loaderbar.scrub.onPress = function() {
clearInterval(videoInterval);
scrubInterval = setInterval(scrubit, 10);
this.startDrag(false, 0, this._y, 212, this._y);
}
loaderbar.scrub.onRelease = loader.scrub.onReleaseOutside = function() {
clearInterval(scrubInterval);
videoInterval = setInterval(videoStatus, 100);
this.stopDrag();
}
loaderbar.loadbar.btnBar.onPress = function() {
var ClickX = Math.round(_xmouse - startPosition);
var barW = Math.round(loaderbar.loadbar._width);
var clickP = Math.round((ClickX / barW) * 100);
var gotoClick = clickP / duration;
clearInterval(videoInterval);
this.loaderbar.scrub._x = ClickX;
ns.seek(Math.floor(gotoClick));
}
loaderbar.loadbar.btnBar.onRelease = loaderbar.loadbar.btnBar.onReleaseOutside = function() {
videoInterval = setInterval(videoStatus, 100);
}
function scrubit() {
ns.seek(Math.floor((loaderbar.scrub._x / 212) * duration));
}
function screenSize(theVideoSize, theVideoFile, theVideoTitle, theVideoIcon) {
theVideoTitle = theVideoTitle + " (" + theVideoSize.toLowerCase() + ")";
switch (theVideoSize.toLowerCase()) {
case "small" :
home.gotoAndStop("small");
ns.close();
theVideoSmall.attachVideo(ns);
ns.play (theVideoFile);
setNowPlaying(theVideoTitle, theVideoIcon);
break;
case "medium" :
home.gotoAndStop("medium");
ns.close();
theVideoMedium.attachVideo (ns);
ns.play (theVideoFile);
setNowPlaying(theVideoTitle, theVideoIcon);
break;
case "large" :
home.gotoAndStop("large");
ns.close();
theVideoLarge.attachVideo (ns);
ns.play (theVideoFile);
setNowPlaying(theVideoTitle, theVideoIcon);
break;
case "hd" :
home.gotoAndStop("hd");
ns.close();
theVideoHD.attachVideo (ns);
ns.play (theVideoFile);
setNowPlaying(theVideoTitle, theVideoIcon);
break;
default:
home.gotoAndStop("small");
ns.close();
theVideoSmall.attachVideo (ns);
ns.play (theVideoFile);
setNowPlaying(theVideoTitle, theVideoIcon);
}
}
function setNowPlaying(lcTitle, liICon)
{
_global.nowPlayingText = lcTitle;
_global.nowPlayingImg = liICon;
nowplaying.nowplayingicon.loadMovie(liICon);
if (nowplaying._alpha == 100)
{
nowplaying.txtNowPlaying.text = lcTitle;
}
}
//Sound Control ************
home.createEmptyMovieClip("vSound", home.getNextHighestDepth());
vSound.attachAudio(ns);
//Create anew sound object
var so:Sound = new Sound(vSound);
//Set the volume to the max
so.setVolume(100);
mute.onRollOver = function() {
if(so.getVolume() != 0) {
this.gotoAndStop("onOver");
}
else {
this.gotoAndStop("muteOver");
}
}
mute.onRollOut = function() {
if(so.getVolume() != 0) {
this.gotoAndStop("on");
}
else {
this.gotoAndStop("mute");
}
}
mute.onRelease = function() {
if(so.getVolume() != 0) {
so.setVolume(0);
this.gotoAndStop("muteOver");
}
else {
so.setVolume(100);
this.gotoAndStop("onOver");
}
}
//XML Loader********************
var videosXmlData = new XML ();
videosXmlData.ignoreWhite = true;
videosXmlData.onLoad = function (success) {
var Videos = this.firstChild.childNodes;
//var vPos = 12;
var vPos = 0;
var hPos = 0;
var panel = home.attachMovie("panel","panel",home.getNextHighestDepth());
for(i=0;i<Videos.length;i++) {
ln = i + 1
var loader = home.panel.attachMovie("loadercontainer","loader"+ln,home.panel.getNextHighestDepth());
loader.vicon.loadMovie(Videos[i].attributes.vThumb);
loader.mvTitle = Videos[i].attributes.vTitle;
loader.mvUrl = Videos[i].attributes.vUrl;
loader.mvDesc = Videos[i].attributes.vDesc;
loader.mvSize = Videos[i].attributes.vSize;
loader.mvIcon = Videos[i].attributes.vThumb;
loader._y = vPos
loader._x = hPos
hPos +=130;
loader.onRollOver = over;
loader.onRollOut = out;
loader.onRelease = released;
}
setPanelLength(hPos);
_global.numOfMovies = i;
}
videosXmlData.load ("videos.xml");
panel.onRollOver = panelOver;
function panelOver() {
this.onEnterFrame = scrollPanel;
delete this.onRollOver;
}
var b = stroke.getBounds(home);
function setPanelLength(PanelLength)
{
_global.xPanelLength = PanelLength-b.xMax-10;
}
function scrollPanel() {
if(_xmouse<b.xMin || _xmouse>b.xMax || _ymouse<b.yMin || _ymouse>b.yMax) {
this.onRollOver = panelOver;
delete this.onEnterFrame;
}
if(numOfMovies > 6){
//** Bounderies for RollOver
if(panel._x >= b.xMin) {
panel._x = b.xMin;
}
if(panel._x <= -_global.xPanelLength) {
panel._x = -_global.xPanelLength;
}
var xdist = _xmouse - centerX;
panel._x += -xdist / 7;
}
}
function released()
{
bufferClip._visible = true;
screenSize(this.mvSize, this.mvUrl, this.mvTitle, this.mvIcon);
}
function over()
{
tooltip._alpha = 100;
tooltip.txtTitle.text = this.mvTitle;
tooltip.txtDesc.text = this.mvDesc;
}
function out()
{
tooltip._alpha = 0;
tooltip.txtTitle.text = "";
tooltip.txtDesc.text = "";
}
btnNowPlaying.onRelease = function ()
{
if (nowplaying._alpha == 100)
{
nowplaying._alpha = 0;
nowplaying.txtNowPlaying.text = "";
} else {
nowplaying._alpha = 100;
nowplaying.txtNowPlaying.text = nowPlayingText;
}
nowplaying.nowplayingicon._alpha = 100;
}
//Function to set the background and border color
function setBGnBD(bgType, color)
{
switch (bgType)
{
case 1 :
var w = bg._width;
var h = bg._height;
bg.bgMask._alpha = 0;
bg.beginFill(color);
bg.moveTo(0, 0);
bg.lineTo(w, 0);
bg.lineTo(w, h);
bg.lineTo(0, h);
bg.lineTo(0, 0);
bg.endFill();
break;
case 2 :
var w = nowplaying.nowplayingbk._width;
var h = nowplaying.nowplayingbk._height;
nowplaying.nowplayingbk._alpha = _nowplayingbgalpha;
nowplaying.nowplayingbk.beginFill(color);
nowplaying.nowplayingbk.moveTo(0, 0);
nowplaying.nowplayingbk.lineTo(w, 0);
nowplaying.nowplayingbk.lineTo(w, h);
nowplaying.nowplayingbk.lineTo(0, h);
nowplaying.nowplayingbk.lineTo(0, 0);
nowplaying.nowplayingbk.endFill();
break;
case 3 :
var w = tooltip.tooltipbk._width;
var h = tooltip.tooltipbk._height;
tooltip.tooltipbk._alpha = _tooltipbgalpha;
tooltip.tooltipbk.beginFill(color);
tooltip.tooltipbk.moveTo(0, 0);
tooltip.tooltipbk.lineTo(w, 0);
tooltip.tooltipbk.lineTo(w, h);
tooltip.tooltipbk.lineTo(0, h);
tooltip.tooltipbk.lineTo(0, 0);
tooltip.tooltipbk.endFill();
break;
default:
//Do Something
}
}
//The param allowFullScreen must be set to true in the applet html.
//<param name="allowFullScreen" value="true" />
function toggleFullScreen()
{
//if normal size, go to fullscreen, else go to normal size
if(Stage["displayState"]=="normal")
{
Stage["displayState"]="fullScreen";
}
else
{
Stage["displayState"]="normal";
}
}
Mil gracias,
Roger.
