Solved

Include AS2 code into an AS3 class

Posted on 2010-09-07
5
1,205 Views
Last Modified: 2013-11-11
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;
netconnection.connect("rtmp://localhost/live");

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];
			}
			callback.onClientData(out);
		}
		
		/** 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 {
			onXMPData(rest);
		}

		/** 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 http://help.adobe.com/en_US/FlashMediaLiveEncoder/3.0/Using/WS5b3ccc516d4fbf351e63e3d11c104ba9cd-7ffe.html) **/
		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 NetClient.as 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: http://www.wowzamedia.com/forums/showthread.php?t=6903

Thanks in advance!
0
Comment
Question by:Caracena
  • 2
5 Comments
 
LVL 39

Accepted Solution

by:
blue-genie earned 500 total points
ID: 33634591
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.
0
 
LVL 6

Author Comment

by:Caracena
ID: 33636223
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 NetClient.as 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.
0
 
LVL 6

Author Comment

by:Caracena
ID: 33639237
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 http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/net/NetStream.html#client). 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 -.-
0
 
LVL 37

Expert Comment

by:CyanBlue
ID: 34059450
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.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
I have found that much of my time doing support ends up being a constant repetition of the same steps to different people.  Early on I stated using web pages with Frequently Asked Questions (FAQs) to alleviate most of the burden.  Sometimes this jus…
The goal of the tutorial is to teach the user how to how to record live broadcast.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now