nwebb banner

   hometutorialsworkphotosflash

 Recommended
 
 Tutorials

The NetStream class onStatus event handler is invoked every time the object posts (tries to inform us of…) a change in status or an error. In order to respond to a post we must create a function like so:
netStreamInstanceName.onStatus = function(infoObject) {
  //code here
}
You may have seen code similar to this before, but if not then here is a brief explanation of what's happening: When we created our instance of the NetStream class which we called ns, it was automatically created with an empty property called onStatus. In the code above we define a function, and pop it into this property (whenever a function is stored inside a class property we then call it a method - so onStatus is a method of the NetStream class), and because we are allowed to define our own function we are able to give each instance of the NetStream class a totally unique method if we so desire. So that's all we're doing above. We create a function and pop it into the empty property.

Whenever NetStream wants to notify us of a change it invokes "onStatus", and so the function we just popped in there will execute.

You will also notice a reference to something I called infoObject. When NetStream invokes the onStatus event handler it passes the handler an object with a couple properties (if you feel more comfortable, you may wish to note that this is similar to passing an array). The first property "code" contains a string that describes the result of the onStatus handler, and the second property "level" contains a string that is either "Status" or "Error".

So, for example, we access the code property like this: infoObject.code

12. It will be easier to understand if we see it in action. For now we will just send our information to a textbox, so create a dynamic textbox (multiline & wordwrap on) and give it an instance name of "feedback". Add the following code above the line videoContainer.attachVideo(ns);

ns.onStatus = function(infoObject) {
	feedback.text += "Status (NetStream)" + newline;
	feedback.text += "Level: "+infoObject.level + newline;
	feedback.text += "Code: "+infoObject.code + newline;
};
All Done Now!

Well that's the essentials covered and therefore enough for this tutorial. If you have any problems download my source files and take a look to see if you can spot any errors you may have made.

Note: For those of you with Macromedia Flash MX Professional 2004 and QuickTime 6.1.1 installed on your system, you can use the FLV Export plug-in to export FLV files from supported video-editing applications, importing these FLV files directly into Flash for use in your Flash documents or dynamically play back external FLV files in Flash documents at runtime.


If you have any suggestions or comments about this or any of my tutorials you can email me at neil@nwebb.co.uk and I will do my best to answer them. Please note that due to the volume of Flash-related emails I get, I now prioritize emails related directly to the tutorials themselves. You may find answers to your questions already posted on Flash forums such as actionscript.org and were-here.com

This, and other tutorials can be found on nwebb.co.uk

Part: 1 2 3 4 5 6