-
As2 to As3 this!
Hi all,
Can somebody please convert this code to as3?
Code:
//////////////////////////Connections///////////////
nc = new NetConnection();
nc.connect("rtmp://ip.com/live/");
nc.onStatus = function(info){
trace(info.code);
if(info.code == "NetConnection.Connect.Success"){
playLive();
}
};
playLive = function(){
ns = new NetStream(nc);
theVideo.attachVideo(ns);
theVideo.attachAudio(ns);
ns.play("radio");
};
///////////////Button/////////////////////////
playButton.onRelease = function() {
ns.pause();
};
-
I haven't ever used these classes so this is just a guess - take a look at the language reference, the example is pretty close to your original code.
PHP Code:
var vid:Video = new Video();
var ns:NetStream;
var nc:NetConnection = new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS, onNCStatus);
nc.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onNCError);
nc.connect('rtmp://ip.com/live/');
playButton.addEventListener(MouseEvent.CLICK, playButtonClicked);
function onNCStatus(e:NetStatusEvent):void{
switch (event.info.code) {
case "NetConnection.Connect.Success":
connectStream();
break;
case "NetStream.Play.StreamNotFound":
trace("Stream not found: " + nc.uri);
break;
}
}
function onNCError(e:SecurityErrorEvent):void{
trace('Security Error: ' + e);
}
function connectStream():void{
ns = new NetStream(nc);
ns.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
vid.attachNetStream(ns);
addChild(vid);
ns.play('radio');
}
function playButtonClicked(e:MouseEvent = null):void{
if(ns == null || ns == undefined) return;
ns.pause();
}
Please use [php] or [code] tags, and mark your threads resolved 8)
-
Originally Posted by neznein9
I haven't ever used these classes so this is just a guess - take a look at the language reference, the example is pretty close to your original code.
PHP Code:
var vid:Video = new Video();
var ns:NetStream;
var nc:NetConnection = new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS, onNCStatus);
nc.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onNCError);
nc.connect('rtmp://ip.com/live/');
playButton.addEventListener(MouseEvent.CLICK, playButtonClicked);
function onNCStatus(e:NetStatusEvent):void{
switch (event.info.code) {
case "NetConnection.Connect.Success":
connectStream();
break;
case "NetStream.Play.StreamNotFound":
trace("Stream not found: " + nc.uri);
break;
}
}
function onNCError(e:SecurityErrorEvent):void{
trace('Security Error: ' + e);
}
function connectStream():void{
ns = new NetStream(nc);
ns.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
vid.attachNetStream(ns);
addChild(vid);
ns.play('radio');
}
function playButtonClicked(e:MouseEvent = null):void{
if(ns == null || ns == undefined) return;
ns.pause();
}
Thanks for the response and I'm sorry i responded so late i was busy, I was testing the code you posted and the following errors came up.
Scene 1, Layer 'Layer 1', Frame 1, Line 11 1120: Access of undefined property event.
Scene 1, Layer 'Layer 1', Frame 1, Line 27 1120: Access of undefined property netStatusHandler.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|