HouseCleaning
At the moment, nearly half of the code has been removed, and we should scan each function and variable and see if it is still in need. Let's roll out.
The following functions have no reference:
scaleVideo()
loadVideo()
pl_orientation
pl
videoLoadInitiated
video_permalink
isSeekAheadTimeLoaded
flashvars
dt_bg
pl_w
pl_y
pl_x
pl_detail
pli_h
pli_w
pl_mask
sh
sh_bg
In XML file, there are two setting attribute: beginCallback and completeCallback, with false value, they are indicating some javascript functions that should be invoked at some point when the program run. So all the code under the condition that they are true will never be reached, and the variables beginCallback, completeCallback, beginCallbackFunction and completeCallbackFunction are all useless.
Since the views of playlist, detail and share are all removed, some variables about them are useless, they are used to store the size and position data of the components, both normal size and :
v_x_mini_pl
v_x_mini_dt
v_x_mini_sh
v_w_mini
v_h_mini
v_x_mini
v_y_mini
v_w_norm
v_h_norm
v_x_norm
v_y_norm
v_sX_norm
v_sY_norm
v_sX_mini
v_sY_mini
meta
as file(house cleaning_1 version)
Get rid of Still
still_c is a MovieClip that in the vid MC, it is a wrapper of the video's thumb-a image indeed. So the effort around it includes to use a Loader to load the still image, and to add it, and to position the layout at runtime.
The sketch is:
internal var still_c:flash.display.MovieClip;
still_c = new flash.display.MovieClip();
vid.addChildAt(still_c, 0);
still_c.addEventListener(flash.events.MouseEvent.MOUSE_DOWN, playDown);
public function playDown(arg1:flash.events.MouseEvent=null):void
{
trace("begin playDown - currentStatus: " + currentStatus);
vid.visible = true;
get_pl();
var loc1:*=currentStatus;
switch (loc1)
{
case "ready":
{
videoTimer.start();
if (autoVidLoad)
{
loadStill();
...................
public function playerLayout():void
{
videoLayout();
vcrLayout();
stillLayout();
...........
public function loadStill():void
{
var stillLoader:flash.display.Loader;
var loc1:*;
stillLoader = null;
if (video_still != "")
{
trace("loading still: " + video_still);
stillLoader = new flash.display.Loader();
stillLoader.contentLoaderInfo.addEventListener(flash.events.Event.COMPLETE, onStillLoaded);
try
{
stillLoader.load(new flash.net.URLRequest(video_still));
}
catch (e:ArgumentError)
{
trace("loadStill", e);
}
}
return;
}
public function onStillLoaded(arg1:flash.events.Event):void
{
still = flash.display.Bitmap(arg1.target.loader.content);
still_c.addChild(still);
stillLayout();
return;
}
public function stillLayout():void
{
if (videoStretch != "uniform")
{
if (videoStretch != "none")
{
if (videoStretch != "exactfit")
{
if (videoStretch == "fill")
{
com.circlecube.Math_cc.resizeMeFill(still_c, stage.stageWidth, stage.stageHeight);
}
}
else
{
com.circlecube.Math_cc.resizeMe(still_c, stage.stageWidth, stage.stageHeight, false);
}
}
else
{
com.circlecube.Math_cc.resizeMe(still_c, videoWidth, videoHeight, true);
still_c.x = stage.stageWidth / 2 - still_c.width / 2;
still_c.y = stage.stageHeight / 2 - still_c.height / 2;
}
}
else
{
com.circlecube.Math_cc.resizeMe(still_c, stage.stageWidth, stage.stageHeight, true);
}
return;
}
remove them, and change
vid.setChildIndex(video, vid.numChildren - 3);
to
vid.setChildIndex(video, vid.numChildren - 2);
change
vid.addChildAt(videofg, 2);
to
vid.addChildAt(videofg, 1);
We also don't need the variables that store the url of still image:
video_still
still
pl_still[]
as file(remove still version)
Continue with Removing Useless Features
DisplayElapsed
displayElapsed, it is used to indicate whether the current time should show the time has elapsed, or the time that left, of the video. And toggleDisplayTime() will response to clicking on current time button, and toggle its value.
Inside clearVideoStatus(),change
if (displayElapsed)
{
vcr.timeCurrent.timeDisplay.text = com.circlecube.Time_cc.secondsToTimeCode(NaN);
}
else
{
vcr.timeCurrent.timeDisplay.text = com.circlecube.Time_cc.secondsToTimeCode(NaN);
}
to
vcr.timeCurrent.timeDisplay.text = com.circlecube.Time_cc.secondsToTimeCode(NaN);
Inside videoStatus(), change
if (displayElapsed)
{
vcr.timeCurrent.timeDisplay.text = com.circlecube.Time_cc.secondsToTimeCode(ns.time);
}
else
{
vcr.timeCurrent.timeDisplay.text = "-" + com.circlecube.Time_cc.secondsToTimeCode(duration - ns.time);
}
to
vcr.timeCurrent.timeDisplay.text = com.circlecube.Time_cc.secondsToTimeCode(ns.time);
as file (remove display elapsed version)
And now, the current time is not acting as button, we should also remove the mouse_over and mouse_out event on it.
Video play loop & continue
Firstly, we notice that inside videoComplete(), the program never reach two if-else blocks:
if (has_playlist && pl_continue)
{
pl_next();
}
else if (loop_count >= 1 || loop == "always")
{
playDown();
loop_count--;
}
so, for now, we can delete pl_next(), because here goes the only one call it, and inside pl_next(), it call pl_first() for sole time, then, we can delete both.
And now let's inspect the variables: has_playlist, pl_continue, loop and loop_count.
pl_continue has declared with initial value false, and never be reset.
has_playlist should be set when creating playlist module, might inside pl_build(), but now there's no reference to it, left it un-initialized.
loop its initial value is 0, be reset when reading xml, but there is no loop attribute in xml, so it is always 0, never be 'always'.
loop_count is the same as loop.
pl_loop
Video Stretching
videoStretch is used to represented the options for displaying video in what dimension. It has initial value "uniform", and is reset when reading xml, it may have following values:
uniform, none, exactfit, fill
And since the xml setting scale value is 'uniform', this var will keep uniform forever. So we remove it and its logic.
inside videoLayout(), change
if (videoStretch != "uniform")
{
if (videoStretch != "none")
{
if (videoStretch != "exactfit")
{
if (videoStretch == "fill")
{
com.circlecube.Math_cc.resizeMeFill(video, stage.stageWidth, stage.stageHeight);
com.circlecube.Math_cc.resizeMeFill(videofg, stage.stageWidth, stage.stageHeight);
}
}
else
{
com.circlecube.Math_cc.resizeMe(video, stage.stageWidth, stage.stageHeight, false);
com.circlecube.Math_cc.resizeMe(videofg, stage.stageWidth, stage.stageHeight, false);
}
}
else
{
com.circlecube.Math_cc.resizeMe(video, videoWidth, videoHeight, true);
video.x = stage.stageWidth / 2 - video.width / 2;
video.y = stage.stageHeight / 2 - video.height / 2;
videofg.x = video.x;
videofg.y = video.y;
}
}
else
{
com.circlecube.Math_cc.resizeMe(video, stage.stageWidth, stage.stageHeight, true);
com.circlecube.Math_cc.resizeMe(videofg, stage.stageWidth, stage.stageHeight, true);
}
to
com.circlecube.Math_cc.resizeMe(video, stage.stageWidth, stage.stageHeight, true);
com.circlecube.Math_cc.resizeMe(videofg, stage.stageWidth, stage.stageHeight, true);
and delete else.
Inside stillLayout(), change:
if (videoStretch != "uniform")
{
if (videoStretch != "none")
{
if (videoStretch != "exactfit")
{
if (videoStretch == "fill")
{
com.circlecube.Math_cc.resizeMeFill(still_c, stage.stageWidth, stage.stageHeight);
}
}
else
{
com.circlecube.Math_cc.resizeMe(still_c, stage.stageWidth, stage.stageHeight, false);
}
}
else
{
com.circlecube.Math_cc.resizeMe(still_c, videoWidth, videoHeight, true);
still_c.x = stage.stageWidth / 2 - still_c.width / 2;
still_c.y = stage.stageHeight / 2 - still_c.height / 2;
}
}
else
{
com.circlecube.Math_cc.resizeMe(still_c, stage.stageWidth, stage.stageHeight, true);
}
to:
com.circlecube.Math_cc.resizeMe(still_c, stage.stageWidth, stage.stageHeight, true);
as file(remove displayelapsed, loop version)
Remove of Style
No text shows up, and then no CSS Style is needed any more:
player_css = new flash.text.StyleSheet();
public function initColors():*
{
trace("init colors");
com.circlecube.Color_cc.setColor(vcr.bar.scrub.inner, color_dark);
com.circlecube.Color_cc.setColor(vcr.bar.scrub.outer, color_light);
com.circlecube.Color_cc.setColor(vcr.bar.playbar.bar, color_accent);
com.circlecube.Color_cc.setColor(vcr.bar.loadbar.bar, color_light);
com.circlecube.Color_cc.setColor(vcr.bar.bar.outline, color_light, 0.4);
com.circlecube.Color_cc.setColor(vcr.timeCurrent, color_light);
com.circlecube.Color_cc.setColor(vcr.timeTotal, color_light);
com.circlecube.Color_cc.setColor(vcr.bg.bar, color_dark);
com.circlecube.Color_cc.setColor(vcr.playB.icon, color_light);
com.circlecube.Color_cc.setColor(vcr.volumeB.speaker, color_light);
com.circlecube.Color_cc.setColor(vcr.volumeB.slider.bar.bar, color_accent);
com.circlecube.Color_cc.setColor(vcr.volumeB.slider.handle.image, color_light);
com.circlecube.Color_cc.setColor(vcr.volumeB.slider.fill, color_dark);
com.circlecube.Color_cc.setColor(vcr.volumeB.slider.bg, color_dark);
myCSS();
............
internal var player_css:flash.text.StyleSheet;
public function myCSS():void
{
myFontSize = stage.stageHeight > stage.stageWidth ? Math.round(stage.stageWidth / 40) : Math.round(stage.stageHeight / 40);
cssAccentColor = "#" + color_accent.toString(16);
cssLightColor = "#" + color_light.toString(16);
player_css.setStyle("body", {"fontSize":myFontSize, "color":cssLightColor, "fontFamily":"Arial,Helvetica,Verdana"});
player_css.setStyle("a:link", {"color":cssAccentColor, "textDecoration":"none"});
player_css.setStyle("a:hover", {"color":cssAccentColor, "textDecoration":"underline"});
player_css.setStyle("h1", {"color":cssAccentColor, "fontSize":myFontSize * 1.5, "fontWeight":"bold"});
player_css.setStyle("h2", {"fontSize":myFontSize * 1.1, "fontWeight":"bold"});
player_css.setStyle("b", {"fontWeight":"bold"});
player_css.setStyle("p", {"fontWeight":"normal", "fontSize":myFontSize});
return;
}
as file (remove css and some non-use vars and plc)