Saturday, July 10, 2010

Flash Video Player Contd...

In AS3.0 custom FLV Player is Implemented by defining the NetConnection Object and passing null to its connect method. NetStream Object is created by passing in a reference to the aforementioned NetConnection object i.e.

  1. var nc:NetConnection=New NetConnection();
  2. nc.connect(null);
  3. var ns:NetStream=new NetStream(nc);
We can create an embedded video object using only code. e.g.

var vid:Video=new Video(320,240);
this.addChild(vid);


Once we have created the video object we now need to connect it to the NetStream object. In AS3.0 we do this by using a method called attachNetStream(). If you want to attach a webcam to the video object you would use the attachCamera() method. Once the NetStream is attached we can begin playing an external FLV the same as before by calling the NetStream.play() method. e.g.


vid.attachNetStream(ns);
ns.play("test.flv");


for responding the events from the NetStream class, First off, you have to provide a callback function for the on MetaData event or Flash will throw errors at you. You need to create an Object that will act as the NetStream's client for the callback event. Once you have setup the onMetaData function for this object you need to set the NetStream client property so it knows where to look. If your FLV contains embedded cue points then you will also need to create an onCuePoint function to handle that call back event.


var netClient:Object=new Object();
netClient.onMetaData=function(meta:Object)
{
   trace(meta.duration);
}
ns.client=netClient;


In order to recieve status messages we use the NetStream.addEventListener() method to define a listener functionto respond to this event. e.g.


ns.addEventListener(NetStatusEvent.NET_STATUS, netstat);


function netstat(stats:NetStatusEvent)
{
   trace(status.info.code);
}

Video Player In Flash

When you use the FLV file format as your distribution method for video content you have two options for serving the video over the Internet:

  1. Hyper Text Transfer Protocol (HTTP) and
  2. Real Time Messaging Protocol(RTMP).
You can use one or both protocols to serve video to your Internet audience.

HTTP is used for progressive video downloads.

RTMP is used for streaming videos.

Tuesday, July 6, 2010

URLStream Object

In some rare cases you will need to get access to the data that you are downloading before its done downloading. To do so, you use a URLStream object in place of a URLLoader.

URLVariables

In addition to loading XML or text files we can load URLVariables.

For loading URLVariables, we can set the property  of the URLLoader.dataFormat to "variable".

You can also use the URLVariables object to send data to a server with a URLRequest.
e.g.

var request:URLRequest=new URLRequest("http://script.php");
var urlVars:URLVariables=new URLVariables();
urlVars.name="josh";
urlVars.hometown="columbus";
request.data=urlVars;
var loader:URLLoader=new URLLoader(request);

Functionality of URLLoader Class

To get data from outside world into our swf we need "URLLoader" class.

The URLLoader takes a URLRequest Object and allows you to load information from that location or send and load information from that location. The URLLoader is an Event Dispatcher, so it uses events to notify any listeners

  • When it begins loading data.
  • If there's an error.
  • What the status of the http request is 
  • When there's any progress and finally
  • When its complete
Load Method is used for loading.

Loading Data From External Files


In AS2.0 "LoadVars" class was used, in AS3.0 it has been replaced by a much richer and more powerful set of classes.
In AS3.0 the first thing you do is create an instance of a "URLRequest" class.

For that flash.net.* Package is used.

To just go to another webpage use flash.net.navigateToURL(URLRequest Object);

GET is used when Data is to be send in address bar and POST is  used when its hidden in the actual HTTP request.

Method of Sending is set by the "method" property of "URLRequest" class. i.e.

var request : URLRequest = new URLRequest("http://server.com");
request.method = "GET";

For sending the data ,"data" property of "URLRequest" class is used.
i.e.
request.data = "name=josh&login=true";

What is difference between AS2.0 and AS3.0 ?

In AS2.0 Display types can't Implement the Polymorphism and they always had a fixed parent-child relationship with other instances.

In AS3.0 All Display types inherit from flash.display.DisplayObject.

AS3.0 provides runtime errors.

Strict typing is preserved at runtime in AS3.0, data mismatches are reported as errors.

AS3.0 has Intrinsic Event Model.

Regular Expressions has been added in AS3.0

E4X i.e. ECMA Script for XML is used in AS3.0 in place of DOM of AS2.0

What is OOPS ?

OOPS: Object Oriented Programming System or Structure, it is  an way of coding which closely resembles the property of evolution in nature.



It constitutes of Class and Objects also called Instances, and it implements three properties, Polymorphism, Encapsulation and Inheritence using the four access controls in ActionScript 3.0, which are:
  1. Public: Open to All.
  2. Private: Reserved for the Class.
  3. Protected: The Class and Subclass or Childclass can use it.
  4. Internal: All the classes in the package can access it.
There is one fifth control too called Final. It is used when we don't want that somebody can extend our class.


Let us consider the example of tyre. It extends the Class Rubber hence Inheritence, how the tyre is made from rubber we don't know hence Encapsulation, now we can create tyre of different types like cycle or car tyre etc which is only possible through polymorphism.