May 28

This post is to highlight the double buffering technique (also known as dynamic buffering) that "should" make video streaming in flash alot smoother without having to prebuffer anything.

This technique works on progressive video download as well as streaming:

var startBufferLength:Number= 2; //keep this in the range 2-4+
var xpandedBufferLength:Number = 15;  //arbitrarily highnc = new NetConnection();
nc.connect(null);
ns = new NetStream(nc);
ns.setBufferTime(3);
ns.autoPlay = false;
ns.onStatus = Delegate.create(this, handleVideoStatus);//(if this was AS3 the syntax will be:
//ns.addEventListener(NetStatusEvent.NET_STATUS, handleVideoStatus);

// if this was Actionscript 3, this following line would be:
// private function handleStatus(event:NetStatusEvent):void 

function handleVideoStatus(infoObject:Object)
{

	switch (infoObject.code) {
		case "NetConnection.Connect.Success":

		break;

		case "NetStream.Buffer.Full":
			ns.bufferTime = xpandedBufferLength;
		break;

		case "NetStream.Buffer.Empty":
			ns.bufferTime = startBufferLength;
		break;

		case "NetStream.Play.Start":
			// the video has started playing, do something here
		break;

		case "NetStream.Play.Stop" :
			// the video has stopped playing (finished)
		break;

	}
}



May 28

Reading the shared object:

var my_so:SharedObject = SharedObject.getLocal("SomeName");
var trackingDate:Date = my_so.data.theDate

writing to a shared object:

var my_so:SharedObject = SharedObject.getLocal("SomeName");
var _date = new Date();
my_so.data.theDate = _date;
my_so.flush(10000);

and clearing a shared object (erasing its content)

var my_so:SharedObject = SharedObject.getLocal("SomeName");
my_so.clear();



May 28

let's imagine this scenario:
A.swf loads B.swf
after load is completed,A.swf needs to execute a function in B.swf called runCommands() for example.. here is the code for that (this is the code inside A.swf):

import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.events.*;
import flash.net.URLRequest;

...

var loaderRequest:URLRequest = new URLRequest("B.swf");
var movieLoader:Loader = new Loader();
movieLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
movieLoader.load(loaderRequest)....

function completeHandler(_event:Event)
{

	var _loaderInfo:LoaderInfo = _event.target as LoaderInfo;
	var loadedObject:Object = _loaderInfo.content;
	loadedObject.runCommands()
}