SWF Example
import flash.net.URLRequest;
import flash.display.Stage;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.text.TextField;
var theLoader:Loader = new Loader();
var myRequest:URLRequest = new URLRequest("idx.swf");
theLoader.load(myRequest);
var loadProgress_txt:TextField = new TextField();
loadProgress_txt.width = 500;
theLoader.contentLoaderInfo.addEventListener(Event.INIT,initHandler);
theLoader.contentLoaderInfo.addEventListener(Event.OPEN,showPreloader);
theLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,showProgress);
theLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,doneLoading);
function initHandler(evt:Event):void {
trace("Init");
MovieClip(LoaderInfo(evt.target).content).stop();
}
function showPreloader(evt:Event):void {
trace("Show preloader");
addChild(loadProgress_txt);
}
function showProgress(evt:ProgressEvent):void {
//trace("Show progress")
loadProgress_txt.text = "loaded:"+evt.bytesLoaded+" from "+evt.bytesTotal;
trace(loadProgress_txt.text);
}
function doneLoading(evt:Event):void {
trace("Done loading")
stop();
removeChild(loadProgress_txt);
addChild(theLoader);
MovieClip(LoaderInfo(evt.target).content).play();
}
stop();
FLV Example
import fl.video.*;
import fl.controls.ProgressBarMode;
// FLV Playback Pro - http://www.communitymx.com/content/article.cfm?page=1&cid=88033
import com.flashsupport.video.FLVPlaybackPro;
var displayFLV:FLVPlaybackPro = new FLVPlaybackPro();
displayFLV.width = 500;
displayFLV.height = 500;
displayFLV.x = 0;
displayFLV.y = 0;
displayFLV.scaleMode = VideoScaleMode.EXACT_FIT;
// Prevent full screen takeover
displayFLV.fullScreenTakeOver = false;
// Set Variables
var flvSource = flvSourceFile.text; // Obtain FLV filename from parent
trace(flvSourceFile.text);
displayFLV.source = flvSource;
// Prevent the FLV from starting until we tell it to
displayFLV.autoPlay = false
displayFLV.align = StageAlign.TOP_LEFT;
displayFLV.addEventListener(VideoEvent.COMPLETE, goNext);
function goNext(e:VideoEvent):void {
nextFrame();
}
// Create event handler functions to control the progressbar
function progressHandler(event:VideoProgressEvent):void
{
var bl = Math.round(event.bytesLoaded/1000);
var bt = Math.round(event.bytesTotal/1000);
// Update progress...
pb.setProgress(bl,bt);
trace(bl + "/" + bt);
stuff.text = bl.toString() + "/" + bt.toString();
if (bl >= bt-5) {
addChild(displayFLV);
removeChild(pb)
displayFLV.play()
}
}
// Set progress bar state
pb.mode = ProgressBarMode.MANUAL;
pb.indeterminate = false;
// Add listeners and load the video
displayFLV.addEventListener(VideoProgressEvent.PROGRESS, progressHandler);
stop();