|
-
Disable external FLV file from playing until fully loaded...?
Hello,
In my project I have five video files that I need to all play simultaneously. I'd like the user to be unable to play them until they are fully loaded, because of course streaming would mean they wouldn't necessarily be playing at synchronised times any more.
So I need to load them all entirely, and have a single button that the user clicks to get them all to play simultaneously. Does anyone have any information on this?
Thanks,
Chris.
-
Senior Member
You can wrote a preloader class and play them once all of them are preloaded.
- The right of the People to create Flash movies shall not be infringed. -
-
So it's possible? Great! Sorry to be a pain but could you point me in the direction of any tutorials that would show me exactly how to do this? Or near enough this concept? Or if it's not a lot of work, any actionscript given would be appreciated.
Thanks cancerinform, you've helped me a good number of times.
-
Senior Member
Here is a script for two flvs to preload, which I once wrote. But it is in AS2 and you need to adjust it. You can choose whether you are using a videoobject or component.
PHP Code:
/*******************************
This is the script for a simple virtual preloader to preload a video.
Parameters:
xDistance: x position of loaderbar
yDistance: y position of loaderbar
barHeight: height of the loaderbar
barColor: hexadecimal color value for the loaderbar fill
ar_items: Array for the video to load
videoComp: Boolean true if the video is played in a component
frame 1 of the movie: (Example)
********************************
import Flashscript.Videopreloader.Videoloader_comp;
var xDist:Number = 10;
var yDist:Number = 100;
var bHeight:Number = 10;
var bColor:Number = 0x000000;
var a_items:Array = ["a.flv", "b.flv"];
var vc:Boolean = true;
vPreloader.loadTheMovie (xDist, yDist, bHeight, bColor, a_items, vc);
*********************************
copyright: Flashscript 2004-2010
*********************************/
//
// we import thr video class
//
import mx.video.*;
//
import mx.utils.Delegate;
//
//class definition
//
class Flashscript.Videopreloader.Videoloader_comp extends MovieClip
{
//
// DEFINING ALL VARIABLES:
//
// for all parameters
//
public var xDistance:Number;
public var yDistance:Number;
public var barHeight:Number;
public var barColor:Number;
public static var ar_items:String;
public var nu_count02:Number;
public static var v_stream:NetStream;
private var videoComp:Boolean;
//
// for the empty movieclips, which are created
//
private var movieLoader:MovieClip;
private var outLine:MovieClip;
private var textLoader:MovieClip;
//
// for the textfields
//
private var bytesField:String;
private var frameField:String;
private var totalField:String;
private var loaderField:String;
//
// for monitoring the loading
//
private var perLoaded:Number;
private var loadedBytes:Number;
private var totalBytes:Number;
private var bytes:Number;
private var frame:Number;
private var preloadMCL:Object;
//
// videoobject or component
//
private var videoPlback1:Object;
private var videoPlback2:Object;
//
// counter variable for the array
//
private static var count:Number;
private static var countVideo:Number;
private var stream_ns1:NetStream;
private var stream_ns2:NetStream;
//
// constructor
//
public function Videoloader_comp ()
{
count = 0;
countVideo = 0;
}
public function loadTheMovie (xDistance, yDistance, barHeight, barColor, ar_items, videoComp):Void
{
//
// and a new NetStream object
//
stream_ns1 = new NetStream (this._parent.connection_nc);
stream_ns2 = new NetStream (this._parent.connection_nc);
//
// passing the parameter variables
//
var xDist:Number = xDistance;
var yDist:Number = yDistance;
var bHeight:Number = barHeight;
var bColor:Number = barColor;
var a_items:Array = ar_items;
var videoComponent:Boolean = videoComp;
//
// ...for the loaderbar
//
this.createEmptyMovieClip ("outLine", 1);
this.createEmptyMovieClip ("movieLoader", 2);
this.createEmptyMovieClip ("textLoader", 3);
this.movieLoader._x = xDist;
this.movieLoader._y = yDist;
this.textLoader._x = xDist;
this.textLoader._y = yDist;
this.outLine._x = xDist;
this.outLine._y = yDist;
//
// initializing the video. We differentiate here if we load into a video component.
//
if (!videoComponent)
{
this._parent.videoPlback1.attachVideo (stream_ns1);
this._parent.videoPlback2.attachVideo (stream_ns2);
}
stream_ns1.play (ar_items[count]);
stream_ns1.pause ();
stream_ns1.onStatus = function (obj:Object)
{
trace (obj.code);
};
//
// creating textfields
//
this.textLoader.createTextField ("bytesField", 4, 0, bHeight + 20, 150, 15);
this.textLoader.bytesField.textColor = bColor;
this.textLoader.createTextField ("frameField", 5, 0, bHeight + 40, 150, 15);
this.textLoader.frameField.textColor = bColor;
this.textLoader.createTextField ("totalField", 6, 0, bHeight + 60, 150, 15);
this.textLoader.totalField.textColor = bColor;
//
// creating the outline for loaderbar
//
if (bColor != null)
{
this.outLine.lineStyle (1, 0x000000, 100);
this.outLine.moveTo (-1, -1);
this.outLine.lineTo (102, -1);
this.outLine.lineTo (102, bHeight + 1);
this.outLine.lineTo (-1, bHeight + 1);
this.outLine.lineTo (-1, -1);
}
//
// loading and monitoring the movie with the MovieClipLoader class
//
this.onEnterFrame = function ()
{
//
// getting total bytes
//
totalBytes = stream_ns1.bytesTotal;
//
// loded bytes defining
//
loadedBytes = stream_ns1.bytesLoaded;
//
// bytes loaded
//
bytes = Math.round ((loadedBytes / 1024) * 1000);
//
// % loaded
//
perLoaded = Math.round ((loadedBytes / totalBytes) * 100);
//
// defining the loading status for loaderbar
//
frame = Math.round ((loadedBytes / (totalBytes / 100)));
if (bColor != null)
{
var lsFrame:Number = frame;
}
else
{
var lbFrame:Number = frame * 10;
}
if (frame > 1)
{
if (bColor != null)
{
//
// creating the fill for loaderbar
//
this.movieLoader.beginFill (bColor, bHeight);
this.movieLoader.moveTo (0, 0);
this.movieLoader.lineTo (lsFrame, 0);
this.movieLoader.lineTo (lsFrame, bHeight);
this.movieLoader.lineTo (0, bHeight);
this.movieLoader.lineTo (0, 0);
this.movieLoader.endFill ();
}
else
{
//
// for use of your own loaderbar, name it loaderBar
//
this.movieLoader.attachMovie ("loaderBar", "loaderBar", 1);
this.movieLoader.loaderBar._xscale = lbFrame;
}
//
// showing the bytes and % loaded in textfield
//
this.textLoader.totalField.text = "total bytes: " + totalBytes;
this.textLoader.bytesField.text = "bytes loaded: " + bytes;
this.textLoader.frameField.text = "% loaded: " + perLoaded;
}
//
// after loading remove all objects and go to indicated frame
//
if (loadedBytes > 0 && loadedBytes >= totalBytes)
{
delete this.onEnterFrame;
//
// we again use different syntax if there is video object or component
//
count++;
if (count < a_items.length)
{
this.loadTheMovie (xDistance, yDistance, barHeight, barColor, ar_items, videoComp);
}
else
{
this.movieLoader._visible = false;
this.outLine._visible = false;
this.textLoader._visible = false;
if (!videoComponent)
{
this.exitVO (ar_items);
}
else
{
this.exitVC (ar_items);
}
}
}
};
}
private function exitVC (ar_items):Void
{
//
// for component
//
this._parent.videoPlback1.contentPath = ar_items[0];
this._parent.videoPlback2.contentPath = ar_items[1];
this._parent.videoPlback.complete = Delegate.create (this, finish);
function finish ()
{
this._parent.videoPlback1.visible = false;
this._parent.videoPlback2.visible = false;
}
}
private function exitVO (ar_items):Void
{
//
// for video object
//
stream_ns1.play (ar_items[0]);
stream_ns2.play (ar_items[1]);
v_stream.onStatus = Delegate.create (this, loadAgain);
function loadAgain (infoObject:Object)
{
trace (infoObject.code);
}
}
}
- The right of the People to create Flash movies shall not be infringed. -
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|