[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Include AS2 code into an AS3 class

Posted on 2010-09-07
5
Medium Priority
?
1,232 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:Cesar Aracena
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 39

Accepted Solution

by:
blue-genie earned 2000 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:Cesar Aracena
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:Cesar Aracena
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The goal of the tutorial is to teach the user how to how to record live broadcast.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

649 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