Hi all, I've got a fla player and I'm trying to get it to display inside a div properly, it looks ok in IE (only after you refresh the page), but none of the other browsers show it properly (only 1/4 of the tv shows).. The flash document size is 336px x 220px and I've placed the tv and remote inside.
I'm using SWFObject to call the flash using this:
<script type="text/javascript">
var so = new SWFObject("tv.swf?videoUrl=video1.flv&imageUrl=image/image1.jpg&tvName=", "DSI", "100%", "100%", "6", "");
so.addVariable("autostart","true");
so.addParam("allowFullScreen", "true");
so.write("flashcontent");
</script>
And it sits inside a div which is also 336px x 220px with a red border (for visibility only).
Here's the URL: http://live.gfwa.360southclients.com/commercial/test.html
Can someone help me out with this to get it to display ok, I'm not so good with flash etc.. :S
Oh and here's the action script file:
package
{
import flash.display.*;
import flash.events.*;
import flash.media.*;
import flash.net.*;
import flash.utils.*;
public class tvplayer extends MovieClip
{
private var seekbarChangeInterval:uint;
private var vid:Video;
private var mute:Boolean;
private var imageUrl:String;
public var remote_mc:MovieClip;
private var realVideoWidth:Number;
private var volumeChangeInterval:uint;
private var videoLoaded:Boolean;
private var currentState:Boolean;
private var req:URLRequest;
private var screenHeight:Number;
private var screenWidth:Number;
private var seekbarHideTimer:Timer;
private var videoUrl:String;
private var realVideoHeight:Number;
private var totalVideoTime:Number;
public var All_mc:MovieClip;
private var xmlLoader:URLLoader;
private var muteHideTimer:Timer;
private var volumeHideTimer:Timer;
private var videoLoadedInterval:uint;
private var imageLoader:Loader;
private var videoLoadedTime:Number;
private var showVideo:Boolean;
private var nc:NetConnection;
private var ns:NetStream;
private var latestVolumeVal:Number;
public function tvplayer() : void
{
nc = new NetConnection();
currentState = false;
screenHeight = 336;
screenWidth = 580;
setValues();
readFlashVars();
addButtonsEvents();
arrangeObjects();
loadImage();
loadVideo();
return;
}// end function
private function videoFinished() : void
{
ns.close();
vid.clear();
All_mc.lcd_mc.removeChild(vid);
All_mc.lcd_mc.imageHolder_mc.alpha = 1;
remote_mc.playpause_mc.play_mc.visible = true;
remote_mc.playpause_mc.pause_mc.visible = false;
clearInterval(videoLoadedInterval);
videoLoaded = false;
currentState = false;
return;
}// end function
public function loadImage() : void
{
try
{
imageLoader = new Loader();
imageLoader.load(new URLRequest(imageUrl));
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, createImage);
}
catch (e:Error)
{
}
return;
}// end function
private function setValues()
{
videoUrl = "video/video1.flv";
imageUrl = "image/image1.jpg";
All_mc.txt.text = "Your Logo";
remote_mc.playpause_mc.pause_mc.visible = false;
mute = false;
latestVolumeVal = 1;
videoLoadedTime = 0;
All_mc.muteDisplay_mc.visible = false;
All_mc.volumeDisplay_mc.visible = false;
All_mc.volumeDisplay_mc.volumeBar_mc.width = latestVolumeVal * 348;
All_mc.seekbarDisplay_mc.visible = false;
muteHideTimer = new Timer(2000, 1);
muteHideTimer.addEventListener(TimerEvent.TIMER, hideMuteDisplay);
volumeHideTimer = new Timer(2000, 1);
volumeHideTimer.addEventListener(TimerEvent.TIMER, hideVolumeDisplay);
seekbarHideTimer = new Timer(2000, 1);
seekbarHideTimer.addEventListener(TimerEvent.TIMER, hideSeekbarDisplay);
stage.addEventListener(FullScreenEvent.FULL_SCREEN, fsEvent);
stage.addEventListener(Event.RESIZE, resizeHandler);
remote_mc.ledOn_mc.alpha = 0;
return;
}// end function
private function hideVolumeDisplay(event:TimerEvent) : void
{
All_mc.volumeDisplay_mc.visible = false;
volumeHideTimer.stop();
return;
}// end function
private function seekDown_mouseDown(event:MouseEvent) : void
{
All_mc.muteDisplay_mc.visible = false;
muteHideTimer.stop();
All_mc.volumeDisplay_mc.visible = false;
volumeHideTimer.stop();
ledon();
ns.pause();
seekDown();
seekbarChangeInterval = setInterval(seekDown, 200);
return;
}// end function
private function metaDataGather(param1:Object) : void
{
realVideoHeight = param1.height;
realVideoWidth = param1.width;
totalVideoTime = param1.duration;
setMovieScale();
return;
}// end function
private function seekDown_mouseUp(event:MouseEvent) : void
{
ns.resume();
if (seekbarChangeInterval)
{
clearInterval(seekbarChangeInterval);
}
seekbarHideTimer.start();
ledoff();
return;
}// end function
private function outButton(event:MouseEvent) : void
{
event.currentTarget.out_mc.alpha = 1;
event.currentTarget.over_mc.alpha = 0;
return;
}// end function
private function updateLoader() : void
{
videoLoadedTime = Math.floor(totalVideoTime * (ns.bytesLoaded / ns.bytesTotal));
return;
}// end function
private function stopdrag(event:MouseEvent) : void
{
remote_mc.stopDrag();
return;
}// end function
function netStatusHandler(event:NetStatusEvent)
{
switch(event.info.code)
{
case "NetStream.Play.StreamNotFound":
{
trace("Unable to locate video");
break;
}
case "NetStream.Play.Stop":
{
videoFinished();
break;
}
case "NetStream.Seek.InvalidTime":
{
break;
}
default:
{
break;
}
}
return;
}// end function
private function volumeUp_mouseDown(event:MouseEvent) : void
{
All_mc.muteDisplay_mc.visible = false;
muteHideTimer.stop();
All_mc.seekbarDisplay_mc.visible = false;
seekbarHideTimer.stop();
ledon();
volumeUp();
volumeChangeInterval = setInterval(volumeUp, 200);
return;
}// end function
private function arrangeFullscreenObjects() : void
{
All_mc.lcd_mc.width = stage.stageWidth;
All_mc.lcd_mc.height = stage.stageHeight;
var _loc_1:int = 0;
All_mc.lcd_mc.y = 0;
All_mc.lcd_mc.x = _loc_1;
var _loc_1:int = 0;
All_mc.y = 0;
All_mc.x = _loc_1;
remote_mc.x = All_mc.lcd_mc.x + All_mc.lcd_mc.width - remote_mc.width - 30;
remote_mc.y = All_mc.lcd_mc.y + All_mc.lcd_mc.height - remote_mc.height - 30;
All_mc.volumeDisplay_mc.x = Math.floor(All_mc.lcd_mc.x + (All_mc.lcd_mc.width - All_mc.volumeDisplay_mc.width) / 2);
All_mc.volumeDisplay_mc.y = All_mc.lcd_mc.y + (All_mc.lcd_mc.height - All_mc.volumeDisplay_mc.height) - 20;
All_mc.seekbarDisplay_mc.y = All_mc.lcd_mc.y + (All_mc.lcd_mc.height - All_mc.seekbarDisplay_mc.height) - 20;
All_mc.seekbarDisplay_mc.x = All_mc.volumeDisplay_mc.x;
All_mc.muteDisplay_mc.x = All_mc.lcd_mc.x + (All_mc.lcd_mc.width - All_mc.muteDisplay_mc.width) - 20;
All_mc.muteDisplay_mc.y = All_mc.lcd_mc.y + 20;
All_mc.txt.visible = false;
return;
}// end function
private function startdrag(event:MouseEvent) : void
{
remote_mc.startDrag();
return;
}// end function
private function clickPlayPause(event:MouseEvent) : void
{
All_mc.lcd_mc.imageHolder_mc.alpha = 0;
if (!videoLoaded)
{
loadVideo();
}
if (currentState)
{
currentState = false;
event.currentTarget.pause_mc.visible = false;
event.currentTarget.play_mc.visible = true;
ns.pause();
}
else
{
currentState = true;
ns.resume();
event.currentTarget.play_mc.visible = false;
event.currentTarget.pause_mc.visible = true;
}
return;
}// end function
private function addButtonsEvents()
{
remote_mc.playpause_mc.buttonMode = true;
remote_mc.playpause_mc.addEventListener(MouseEvent.CLICK, clickPlayPause);
remote_mc.playpause_mc.addEventListener(MouseEvent.MOUSE_DOWN, function ()
{
ledon();
return;
}// end function
);
remote_mc.playpause_mc.addEventListener(MouseEvent.MOUSE_UP, function ()
{
ledoff();
return;
}// end function
);
remote_mc.playpause_mc.play_mc.addEventListener(MouseEvent.MOUSE_OVER, overButton);
remote_mc.playpause_mc.play_mc.addEventListener(MouseEvent.MOUSE_OUT, outButton);
remote_mc.playpause_mc.pause_mc.addEventListener(MouseEvent.MOUSE_OVER, overButton);
remote_mc.playpause_mc.pause_mc.addEventListener(MouseEvent.MOUSE_OUT, outButton);
remote_mc.fullscreen_mc.buttonMode = true;
remote_mc.fullscreen_mc.addEventListener(MouseEvent.CLICK, clickFullscreen);
remote_mc.fullscreen_mc.addEventListener(MouseEvent.MOUSE_OVER, overButton);
remote_mc.fullscreen_mc.addEventListener(MouseEvent.MOUSE_OUT, outButton);
remote_mc.fullscreen_mc.addEventListener(MouseEvent.MOUSE_DOWN, function ()
{
ledon();
return;
}// end function
);
remote_mc.fullscreen_mc.addEventListener(MouseEvent.MOUSE_UP, function ()
{
ledoff();
return;
}// end function
);
remote_mc.remoteBg_mc.buttonMode = true;
remote_mc.remoteBg_mc.addEventListener(MouseEvent.MOUSE_DOWN, startdrag);
remote_mc.remoteBg_mc.addEventListener(MouseEvent.MOUSE_UP, stopdrag);
remote_mc.mute_mc.buttonMode = true;
remote_mc.mute_mc.addEventListener(MouseEvent.CLICK, toggleMute);
remote_mc.mute_mc.addEventListener(MouseEvent.MOUSE_OVER, overButton);
remote_mc.mute_mc.addEventListener(MouseEvent.MOUSE_OUT, outButton);
remote_mc.mute_mc.addEventListener(MouseEvent.MOUSE_DOWN, function ()
{
ledon();
return;
}// end function
);
remote_mc.mute_mc.addEventListener(MouseEvent.MOUSE_UP, function ()
{
ledoff();
return;
}// end function
);
remote_mc.volumeUp_mc.buttonMode = true;
remote_mc.volumeUp_mc.addEventListener(MouseEvent.MOUSE_DOWN, volumeUp_mouseDown);
remote_mc.volumeUp_mc.addEventListener(MouseEvent.MOUSE_UP, volumeUp_mouseUp);
remote_mc.volumeUp_mc.addEventListener(MouseEvent.MOUSE_OVER, overButton);
remote_mc.volumeUp_mc.addEventListener(MouseEvent.MOUSE_OUT, outButton);
remote_mc.volumeDown_mc.buttonMode = true;
remote_mc.volumeDown_mc.addEventListener(MouseEvent.MOUSE_DOWN, volumeDown_mouseDown);
remote_mc.volumeDown_mc.addEventListener(MouseEvent.MOUSE_UP, volumeDown_mouseUp);
remote_mc.volumeDown_mc.addEventListener(MouseEvent.MOUSE_OVER, overButton);
remote_mc.volumeDown_mc.addEventListener(MouseEvent.MOUSE_OUT, outButton);
remote_mc.forward_mc.buttonMode = true;
remote_mc.forward_mc.addEventListener(MouseEvent.MOUSE_DOWN, seekUp_mouseDown);
remote_mc.forward_mc.addEventListener(MouseEvent.MOUSE_UP, seekUp_mouseUp);
remote_mc.forward_mc.addEventListener(MouseEvent.MOUSE_OVER, overButton);
remote_mc.forward_mc.addEventListener(MouseEvent.MOUSE_OUT, outButton);
remote_mc.rewind_mc.buttonMode = true;
remote_mc.rewind_mc.addEventListener(MouseEvent.MOUSE_DOWN, seekDown_mouseDown);
remote_mc.rewind_mc.addEventListener(MouseEvent.MOUSE_UP, seekDown_mouseUp);
remote_mc.rewind_mc.addEventListener(MouseEvent.MOUSE_OVER, overButton);
remote_mc.rewind_mc.addEventListener(MouseEvent.MOUSE_OUT, outButton);
return;
}// end function
private function seekUp_mouseDown(event:MouseEvent) : void
{
All_mc.muteDisplay_mc.visible = false;
muteHideTimer.stop();
All_mc.volumeDisplay_mc.visible = false;
volumeHideTimer.stop();
ledon();
seekUp();
seekbarChangeInterval = setInterval(seekUp, 100);
return;
}// end function
private function volumeDown() : void
{
volumeHideTimer.stop();
if (ns.soundTransform.volume > 0)
{
if (ns.soundTransform.volume - 0.1 <= 0)
{
ns.soundTransform = new SoundTransform(0);
latestVolumeVal = 0;
}
else
{
ns.soundTransform = new SoundTransform(ns.soundTransform.volume - 0.1);
latestVolumeVal = ns.soundTransform.volume;
}
}
All_mc.volumeDisplay_mc.volumeBar_mc.width = latestVolumeVal * 348;
All_mc.volumeDisplay_mc.visible = true;
return;
}// end function
private function seekUp_mouseUp(event:MouseEvent) : void
{
if (seekbarChangeInterval)
{
clearInterval(seekbarChangeInterval);
}
seekbarHideTimer.start();
ledoff();
return;
}// end function
private function overButton(event:MouseEvent) : void
{
event.currentTarget.over_mc.alpha = 1;
event.currentTarget.out_mc.alpha = 0;
return;
}// end function
private function ledon() : void
{
remote_mc.ledOn_mc.alpha = 1;
remote_mc.ledOff_mc.alpha = 0;
return;
}// end function
private function seekUp() : void
{
if (ns.time < totalVideoTime)
{
if (ns.time + 2 >= videoLoadedTime)
{
ns.seek(videoLoadedTime);
}
else
{
ns.seek(ns.time + 2);
}
}
All_mc.seekbarDisplay_mc.seekbar_mc.width = ns.time / totalVideoTime * 348;
All_mc.seekbarDisplay_mc.visible = true;
return;
}// end function
private function loadVideo() : void
{
videoLoaded = true;
nc.connect(null);
ns = new NetStream(nc);
vid = new Video();
ns.client = new Object();
ns.bufferTime = 3;
ns.play(videoUrl);
ns.client.onMetaData = metaDataGather;
ns.pause();
vid.attachNetStream(ns);
vid.smoothing = true;
All_mc.lcd_mc.addChild(vid);
ns.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
ns.soundTransform = new SoundTransform(latestVolumeVal);
videoLoadedInterval = setInterval(updateLoader, 100);
return;
}// end function
private function volumeUp_mouseUp(event:MouseEvent) : void
{
if (volumeChangeInterval)
{
clearInterval(volumeChangeInterval);
}
volumeHideTimer.start();
ledoff();
return;
}// end function
private function seekDown() : void
{
if (ns.time > 0)
{
if (ns.time - 2 <= 0)
{
ns.seek(0);
}
else
{
ns.seek(ns.time - 2);
}
}
All_mc.seekbarDisplay_mc.seekbar_mc.width = ns.time / totalVideoTime * 348;
All_mc.seekbarDisplay_mc.visible = true;
return;
}// end function
private function volumeDown_mouseDown(event:MouseEvent) : void
{
All_mc.muteDisplay_mc.visible = false;
muteHideTimer.stop();
All_mc.seekbarDisplay_mc.visible = false;
seekbarHideTimer.stop();
ledon();
volumeDown();
volumeChangeInterval = setInterval(volumeDown, 200);
return;
}// end function
private function readFlashVars()
{
var paramObj:Object;
try
{
paramObj = stage.loaderInfo.parameters;
if (paramObj.videoUrl != null)
{
videoUrl = paramObj.videoUrl;
}
if (paramObj.imageUrl != null)
{
imageUrl = paramObj.imageUrl;
}
if (paramObj.tvName != null)
{
All_mc.txt.text = paramObj.tvName;
}
if (paramObj.screenHeight != null)
{
screenHeight = paramObj.screenHeight;
}
if (paramObj.screenWidth != null)
{
screenWidth = paramObj.screenWidth;
}
}
catch (error:Error)
{
}
return;
}// end function
private function volumeUp() : void
{
if (mute)
{
mute = false;
}
volumeHideTimer.stop();
if (ns.soundTransform.volume < 1)
{
if (ns.soundTransform.volume + 0.1 >= 1)
{
ns.soundTransform = new SoundTransform(1);
latestVolumeVal = 1;
}
else
{
ns.soundTransform = new SoundTransform(ns.soundTransform.volume + 0.1);
latestVolumeVal = ns.soundTransform.volume;
}
}
All_mc.volumeDisplay_mc.volumeBar_mc.width = latestVolumeVal * 348;
All_mc.volumeDisplay_mc.visible = true;
return;
}// end function
private function clickFullscreen(event:MouseEvent) : void
{
if (stage.displayState == StageDisplayState.NORMAL)
{
stage.displayState = StageDisplayState.FULL_SCREEN;
}
else
{
stage.displayState = StageDisplayState.NORMAL;
}
return;
}// end function
private function ledoff() : void
{
remote_mc.ledOn_mc.alpha = 0;
remote_mc.ledOff_mc.alpha = 1;
return;
}// end function
private function hideSeekbarDisplay(event:TimerEvent) : void
{
All_mc.seekbarDisplay_mc.visible = false;
seekbarHideTimer.stop();
return;
}// end function
private function toggleMute(event:MouseEvent) : void
{
All_mc.volumeDisplay_mc.visible = false;
volumeHideTimer.stop();
if (mute)
{
mute = false;
muteHideTimer.stop();
All_mc.muteDisplay_mc.muteOn_mc.alpha = 0;
All_mc.muteDisplay_mc.visible = true;
ns.soundTransform = new SoundTransform(latestVolumeVal);
muteHideTimer.start();
}
else
{
muteHideTimer.stop();
latestVolumeVal = ns.soundTransform.volume;
All_mc.muteDisplay_mc.muteOn_mc.alpha = 1;
All_mc.muteDisplay_mc.visible = true;
mute = true;
ns.soundTransform = new SoundTransform(0);
}
return;
}// end function
private function volumeDown_mouseUp(event:MouseEvent) : void
{
if (volumeChangeInterval)
{
clearInterval(volumeChangeInterval);
}
volumeHideTimer.start();
ledoff();
return;
}// end function
private function arrangeObjects()
{
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
All_mc.x = All_mc.stage.stageWidth / 2 - (screenWidth + 40) / 2;
All_mc.y = All_mc.stage.stageHeight / 2 - (screenHeight + 55) / 2;
var _loc_1:int = 20;
All_mc.lcd_mc.y = 20;
All_mc.lcd_mc.x = _loc_1;
All_mc.lcd_mc.scree_bg.width = screenWidth;
All_mc.lcd_mc.scree_bg.height = screenHeight;
var _loc_1:int = 0;
All_mc.tv_bg.y = 0;
All_mc.tv_bg.x = _loc_1;
All_mc.tv_bg.width = screenWidth + 40;
All_mc.tv_bg.height = screenHeight + 55;
All_mc.foot_mc.y = All_mc.tv_bg.height - 12;
All_mc.foot_mc.x = Math.floor((All_mc.tv_bg.width - All_mc.foot_mc.width) / 2);
All_mc.txt.visible = true;
All_mc.txt.y = All_mc.lcd_mc.y + screenHeight + 5;
All_mc.txt.x = All_mc.tv_bg.x + Math.floor((All_mc.tv_bg.width - All_mc.txt.textWidth) / 2);
remote_mc.x = All_mc.x + (screenWidth + 40) - remote_mc.width;
remote_mc.y = All_mc.y + (screenHeight + 55) - remote_mc.height;
All_mc.volumeDisplay_mc.x = Math.floor(All_mc.lcd_mc.x + (screenWidth - All_mc.volumeDisplay_mc.width) / 2);
All_mc.volumeDisplay_mc.y = All_mc.lcd_mc.y + (screenHeight - All_mc.volumeDisplay_mc.height) - 20;
All_mc.seekbarDisplay_mc.y = All_mc.lcd_mc.y + (screenHeight - All_mc.seekbarDisplay_mc.height) - 20;
All_mc.seekbarDisplay_mc.x = All_mc.volumeDisplay_mc.x;
All_mc.muteDisplay_mc.x = All_mc.lcd_mc.x + (screenWidth - All_mc.muteDisplay_mc.width) - 20;
All_mc.muteDisplay_mc.y = All_mc.lcd_mc.y + 20;
return;
}// end function
private function fsEvent(event:FullScreenEvent)
{
if (stage.displayState == StageDisplayState.NORMAL)
{
arrangeObjects();
All_mc.lcd_mc.width = screenWidth;
All_mc.lcd_mc.height = screenHeight;
}
else
{
arrangeFullscreenObjects();
}
return;
}// end function
private function hideMuteDisplay(event:TimerEvent) : void
{
All_mc.muteDisplay_mc.visible = false;
muteHideTimer.stop();
return;
}// end function
private function createImage(event:Event) : void
{
var _loc_2:Bitmap = null;
_loc_2 = Bitmap(imageLoader.contentLoaderInfo.content);
_loc_2.smoothing = true;
_loc_2.width = screenWidth;
_loc_2.height = screenHeight;
All_mc.lcd_mc.imageHolder_mc.addChild(_loc_2);
return;
}// end function
private function setMovieScale() : void
{
if (screenWidth / screenHeight >= realVideoWidth / realVideoHeight)
{
vid.height = screenHeight;
vid.width = realVideoWidth / realVideoHeight * screenHeight;
vid.x = (screenWidth - vid.width) / 2;
vid.y = 0;
}
else
{
vid.width = screenWidth;
vid.height = realVideoHeight / realVideoWidth * screenWidth;
vid.y = (screenHeight - vid.height) / 2;
vid.x = 0;
}
return;
}// end function
function resizeHandler(event:Event) : void
{
All_mc.x = All_mc.stage.stageWidth / 2 - All_mc.width / 2;
All_mc.y = All_mc.stage.stageHeight / 2 - All_mc.height / 2;
return;
}// end function
}
}