A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: As2 to As3 this!

  1. #1
    Junior Member
    Join Date
    Sep 2011
    Posts
    6

    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();
    };

  2. #2
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    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_STATUSonNCStatus);
    nc.addEventListener(SecurityErrorEvent.SECURITY_ERRORonNCError);
    nc.connect('rtmp://ip.com/live/');

    playButton.addEventListener(MouseEvent.CLICKplayButtonClicked);

    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_STATUSnetStatusHandler);
        
    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)

  3. #3
    Junior Member
    Join Date
    Sep 2011
    Posts
    6
    Quote Originally Posted by neznein9 View Post
    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_STATUSonNCStatus);
    nc.addEventListener(SecurityErrorEvent.SECURITY_ERRORonNCError);
    nc.connect('rtmp://ip.com/live/');

    playButton.addEventListener(MouseEvent.CLICKplayButtonClicked);

    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_STATUSnetStatusHandler);
        
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center