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

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()
}



Dec 2

Creating custom events in AS3 is really easy, and very powerful. example:

lets say that there is a custom event that should be fired when a "Tween Lite" animation is done playing. we start by creating the custom event :

package  {
	import flash.events.*;

	public class FinishedEvent extends Event{

		private var trackingValue:String;
		public static var DO_SOMETHING= "do_something"

		public function FinishedEvent(type:String , someValue:String) {
 			super(type);
			trackingValue = someValue;

		}

		public function getDispatcherName()
 		{
 			return  trackingValue;
 		}
	}
}

Read the rest of this entry »




Oct 30

Static classes are life savers for those who want a central data hubs where all shared variables are stored and accessed and modified. Some programmers think that this is dangerous since there is no real control over who gets to do what with the variables.. but for a scenario where several objects need to access the same data.. I can't think of better ways of doing so.

here's an example of a static class:

package com.packageName{

	public class DataStore{
		static var _DS:DataStore;
		static var dataArray:Array;

		public function DataStore(){
			// write something here
		}

		public static function getInstance(): DataStore	{
			if (_DS == null) _DS = new DataStore();
			return _DS;
		}

		public function doSomething(){
			// write code here
		}
	}
}

and then to call the function doSomething from this class, this is the way it's called:

com.packageName.DataStore.getInstance().doSomething();



Oct 30

I always try to opt from using the flv player component.. although it saves us half the work when it comes to accessing the properties and methods, sometimes it is still very heavy (in size) compared to this approach that really doesn't add anything worth mentioning

import flash.media.SoundTransform;import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;

public class videoPlayer
{
	public function videoPlayer():void
	{

		var customClient = new Object();
		customClient.onMetaData = metaDataHandler;

		var nc = new NetConnection();
		nc.connect(null);

		var ns = new NetStream(nc);
		ns.client = customClient;
		var vid = new Video(320, 240);
		vid.name = "vid";

 		this.addChild(vid);
		vid.attachNetStream(ns);
 		ns.play("videos/videoSample.flv");

		st = new SoundTransform();
 		st.volume=0.5;

		ns.soundTransform=st;
	}

	public function metaDataHandler(infoObject:Object):void {
		for (var prop in infoObject){
			trace(prop+" : "+infoObject[prop]);
		}
	}

}



Sep 19

I am not sure that this is the best or only way of doing it.. but here's what I found so far
what used to be _root.mcName in AS2 is gone... and now the while concept of root is also gone

according to Adobe (from the Flash CS3 help file)

the root property is the top-most display object in the portion of the display list's tree structure represented by that SWF file

however, if you have an object on the stage with name chalk for example you can't access it by saying: root.chalk

because root is the parent displayObject of a stage, where objects are added.

so, on the document class or on the frames, if you write:
Read the rest of this entry »




Sep 19

One of the biggest changes to Actiosncript 3.0 for me (which took me forever to figure out) is the method to add an object from the library by its identifier, in case that identifier was ordered.

take this screenshot for example:

library.jpg

to add an instance of the switchButtons movieClip to the stage all you have to write is:

var sb = new switchButtons();
stage.addChild(sb);

Read the rest of this entry »