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;
}
}
]]>
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();
]]>we instantiate a certain number of instances of object A on the stage (_root) .. and we want each object to be receive a different value, and have that object do something with it
a real life example would be: create a client object and pass the client name as an argument to that object.
and let’s assume that we have a complex class hierarchy that requires code optimization, which generally means that we need to know how to find the code without scrolling through a 5 page long classes.
for that, we can create an Event Manager class that listens to events from all objects in the structure and handles the calls and manages the data.
a simple example would be:
import EventManager.*;
class caller{
function caller(message:String){
EventManager.getInstance().setDataChange(message);
}
}
which will trigger an event-change data event on creation.
this class imports a static class called EventManager which catches the dispatched event and based on its type handles the passed Data.
so this class looks like this:
class EventManager {static var _EM:EventManager ;
static var broadcaster:Object
var listener:Object;
function EventManager(){
broadcaster = new Object();
AsBroadcaster.initialize(broadcaster);
listener = new Object();
listener.onSendEevent = handleEvent;
broadcaster.addListener(listener);
}
static function getInstance (Void): EventManager {
if (_EM == null) _EM = new EventManager();
return _EM;
}
private function handleEvent(message){
// do somethig with the Data
trace("Recieved Message: "+message)
}
public function setDataChange(message:String){
broadcaster.broadcastMessage("onSendEevent" , message);
}
}
and finally, on the main class (where objects are created) this is the final code:
import caller.*;
for (var i:Number=0; i<10; 0++){
this["callerObject"+i] = new caller("Object Name:"+i);
}
so everytime an object is created, the caller object fires an event that carries the object name as content. once fired, the EventManager will be listening to this event, and will collect the name of the object and does something with it (here it traces the name, but in other cases we will most probably save the names to databases or add them to array, etc…)
so the output of these lines of code would be:
Recieved Message: Object Name 0
Recieved Message: Object Name 1
Recieved Message: Object Name 2
Recieved Message: Object Name 3
Recieved Message: Object Name 4
Recieved Message: Object Name 5
Recieved Message: Object Name 6
Recieved Message: Object Name 7
Recieved Message: Object Name 8
Recieved Message: Object Name 9
import com.mosesSupposes.fuse.*;
class customClass{
// constructor
function customClass(){
// this has to be called in the
// constructor function or the
// onLoad function to register the classes
ZigoEngine.register( Fuse, PennerEasing );
var AnimVarFuse = new Fuse();
AnimVar.push(
{
target:this.child_mc,
alpha:100 ,
seconds:0.5,
delay:0.5
},
{
scope:this,
func:functionName
}
);
AnimVar.start();
}
function functionName(){
// this is a function that will be called
// once the animation is over
// the scope refers to where
// the function is declared.. the scope
// can be _root if the function is on
// the highest level
}
}
if two or more objects need to be animated in sequence (object 2 starts animating after object 1 is done animating) this is how the fuse code should look:
AnimVar.push(
{
target:this.child_mc1,
alpha:100 ,
seconds:0.5,
delay:0.5
},
{
target:this.child_mc2,
alpha:100 ,
seconds:0.5,
delay:0.5
},
{
scope:this,
func:functionName
}
);
AnimVar.start();
The since there’s a delay value pushed to the execution queue in the fuse object, this means that after the first object will finish animating then there will be a pause of 0.5 seconds and then the second animation will start
The function part is optional. it is not always required to call a function after the animation is done
]]>