Include AS2 code into an AS3 class

Hi everybody,

I am completely new to AS and I'm trying to make something work between a media streaming server and a flash media player.

I have to include this code:

var netconnection:NetConnection = new NetConnection();
var clientObj:Object = new Object();
clientObj.streamStats = function(streamName:String,currSeq:String,msg:String,date:String):void
	trace("Stream stats. Name: " + streamName + " currSeq: " + currSeq + " msg: " + msg + " date: " + date);
netconnection.client = clientObj;

Open in new window

into this file:
 * Object that catches and forwards calls invoked by NetStream / NetConnection.
package com.longtailvideo.jwplayer.utils {
	public dynamic class NetClient {
		/** Function to callback all events to **/
		private var callback:Object;
		/** Constructor. **/
		public function NetClient(cbk:Object):void {
			callback = cbk;
		/** Forward calls to callback **/
		private function forward(dat:Object, typ:String):void {
			dat['type'] = typ;
			var out:Object = new Object();
			for (var i:Object in dat) {
				out[i] = dat[i];
		/** Checking the available bandwidth. **/
		public function close(... rest):void {
			forward({close: true}, 'close');
		/** Checking the available bandwidth. **/
		public function onBWCheck(... rest):Number {
			return 0;
		/** Receiving the bandwidth check result. **/
		public function onBWDone(... rest):void {
			if (rest.length > 0) {
				forward({bandwidth: rest[0]}, 'bandwidth');
		/** Captionate caption handler. **/
		public function onCaption(cps:String, spk:Number):void {
			forward({captions: cps, speaker: spk}, 'caption');
		/** Captionate metadata handler. **/
		public function onCaptionInfo(obj:Object):void {
			forward(obj, 'captioninfo');
		/** Cuepoint handler. **/
		public function onCuePoint(obj:Object):void {
			forward(obj, 'cuepoint');
		/** CDN subscription handler. **/
		public function onFCSubscribe(obj:Object):void {
			forward(obj, 'fcsubscribe');
		/** Get headerdata information from netstream class. **/
		public function onHeaderData(obj:Object):void {
			var dat:Object = new Object();
			var pat:String = "-";
			var rep:String = "_";
			for (var i:String in obj) {
				var j:String = i.replace("-", "_");
				dat[j] = obj[i];
			forward(dat, 'headerdata');
		/** Image data (iTunes-style) handler. **/
		public function onID3(... rest):void {
			forward(rest[0], 'id3');
		/** Image data (iTunes-style) handler. **/
		public function onImageData(obj:Object):void {
			forward(obj, 'imagedata');
		/** Lastsecond call handler. **/
		public function onLastSecond(obj:Object):void {
			forward(obj, 'lastsecond');
		/** Get metadata information from netstream class. **/
		public function onMetaData(obj:Object):void {
			forward(obj, 'metadata');
		/** Receive NetStream playback codes. **/
		public function onPlayStatus(... rest):void {
			for each (var dat:Object in rest) {
				if (dat && dat.hasOwnProperty('code')) {
					if (dat.code == "NetStream.Play.Complete") {
						forward(dat, 'complete');
					} else {
						forward(dat, 'playstatus');
		/** Quicktime broadcaster pixel. **/
		public function onSDES(... rest):void {
			forward(rest[0], 'sdes');
		/** Receiving the bandwidth check result. **/
		public function onXMPData(... rest):void {
			forward(rest[0], 'xmp');
		public function onXMP(... rest):void {

		/** RTMP Sample handler (what is this for?). **/
		public function RtmpSampleAccess(... rest):void {
			forward(rest[0], 'rtmpsampleaccess');
		/** Textdata handler (MP4 text tracks). **/
		public function onTextData(obj:Object):void {
			forward(obj, 'textdata');
		/** TimeCode handler (see **/
		public function onFI(obj:Object):void {
			forward(obj, 'timecode');

Open in new window

Can anyone tell me what to do here? I've read the file about 100 times and can't figure it out. The file is from the JW Player version 5.2 and I'm trying to make it detect a live stream from a Wowza Media Server so it interrupts the playlist and start showing the live feed.

The source for the implementation is here:

Thanks in advance!
Cesar AracenaPHP EnthusiastAsked:
Who is Participating?
blue-genieConnect With a Mentor Commented:
I'm going to put my head on a block here and say you can't just combine the AS2 and AS3 code.
pick one and rewrite your code accordingly.
you can for example load a AS2 swf into AS3, but they can't "tallk" to each other.
Cesar AracenaPHP EnthusiastAuthor Commented:
Hi blue-genie,

That was I was thinking... but there must be a way for someone with a good knowledge in AS to convert this callback and add it in the code (the long part).

The Wowza instructions are "To see the results in Flash, add this callback to the NetConnection object:
Actionscript" and in the JW Player, the best place to put that code in is in that file called which I copied (the longest code).

So, the NetConnection part of the code I don't care about... it's the "clientObj" I can't figure out how to insert in there.

Thanks again.
Cesar AracenaPHP EnthusiastAuthor Commented:
Of course I'm asking the same question in the JW Player support forums and here's they latest answer:

[QUOTE]I can't really provide code for you, but I can tell you how the NetClient class works. If you set the NetStream.client property to some object, the stream will call all of its callback functions on this object (see In the JWPlayer, the NetClient class is used for this purpose, and all of the NetStream callbacks are defined here.

When one of the callbacks are received, the NetClient class packages up the data and sends it back to the MediaProvider, by calling the provider's onClientData() function, passing the data back that way.[/QUOTE]

Can anyone figure this out? I'm starting to pull my hair out -.-
This question has been classified as abandoned and is being closed as part of the Cleanup Program.  See my comment at the end of the question for more details.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.