dcsimg
A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: NetConnection error in separate class

  1. #1
    Junior Member
    Join Date
    Jul 2007
    Posts
    23

    NetConnection error in separate class

    I get this error:

    Code:
    ArgumentError: Error #2126: NetConnection object must be connected.
    	at flash.net::NetStream/construct()
    	at flash.net::NetStream()
    	at com.ourmedia.utilities::GetFrame$cinit()
    	at global$init()
    	at OMPlayer_fla::MainTimeline/frame1()
    Error #2044: Unhandled AsyncErrorEvent:. text=Error #2095: flash.net.NetStream was unable to invoke callback onMetaData. error=ReferenceError: Error #1069: Property onMetaData not found on flash.net.NetStream and there is no default value.
    	at vidPlayer_fla::MainTimeline/frame1()
    when I have this call in my main player file:

    Code:
    GetFrame.myFrame(finalUrl);
    Which refers to this file - which seems like a complete enough function to me to not generate an error:

    Code:
    package com.ourmedia.utilities {
    import flash.media.*;
    import flash.net.*;
    
        public class GetFrame {
    		public static var theString:String;
    		public static var connected:NetConnection = new NetConnection();
    		public static var nStrm:NetStream = new NetStream(connected);
    		public static var video4frame:Video = new Video();
    		public static var BUFFER_TIME:Number = 8;
    
    		public static function myFrame(theString){
    			connected.connect(null);
    			video4frame.attachNetStream(nStrm);
    			//video_mc.addChild(video);
    			nStrm.play(theString);
    			nStrm.pause();
    		}
        }
    }

    anybody get this one before?

    Am I not able to create a connection in a package - independent of the net connection I'm using for playing the main video?
    Overall I know creating video playback functions in AS3 pretty well I think, but I'm trying to get into separating some functions into packages, and this seems to be a bad start.

  2. #2
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,046
    Your best best would be to do this:
    Code:
    package com.ourmedia.utilities {
    import flash.media.*;
    import flash.net.*;
    
        public class GetFrame {
    		public static var theString:String;
    		public static var connected:NetConnection;
    		public static var nStrm:NetStream;
    		public static var video4frame:Video = new Video();
    		public static var BUFFER_TIME:Number = 8;
    
    		public static function myFrame(theString){
    			connected = new NetConnection();
    			connected.connect(null);
    			nStrm = new NetStream(connected);
    			video4frame.attachNetStream(nStrm);
    			//video_mc.addChild(video);
    			nStrm.play(theString);
    			nStrm.pause();
    		}
        }
    }
    You can't declare the new NetStream(connected) in the definition because connected.connect(null) is being called in the constructor, so things would be processed out of order.

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