You are getting this error because NetConnection object is not yet
connected, message is quite clear.
The way you are doing things might not work on slow network or internet,
because it takes time to make connection before you can use this object for
any purpose.
I suggest you using NetConnection events (NET_sT to be sure when
NetConnection object is connected and do the further processing.
You can find a working example in Flex2 docs, I don't see the example in
Flex 2.0.1 docs so I am pasting it here.
package {
import flash.display.Sprite;
import flash.events.NetStatusEvent;
import flash.events.SecurityErrorEvent;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
public class VideoExample extends Sprite {
private var videoUrl:String = "Video.flv";
private var connection:NetConnection;
private var stream:NetStream;
public function VideoExample() {
connection = new NetConnection();
connection.addEventListener(NetStatusEvent.NET_STATUS,
netStatusHandler);
connection.addEventListener(SecurityErrorEvent.SECURITY_ERROR,
securityErrorHandler);
connection.connect(null);
}
private function netStatusHandler(event:NetStatusEvent):void {
switch (event.info.code) {
case "NetConnection.Connect.Success":
connectStream();
break;
}
}
private function securityErrorHandler(event:SecurityErrorEvent):void {
trace("securityErrorHandler: " + event);
}
private function connectStream():void {
var stream:NetStream = new NetStream(connection);
var video:Video = new Video();
video.attachNetStream(stream);
stream.play(videoUrl);
addChild(video);
}
}
}
hope it helps..
-abdul
file:///D:/downloads/Flex2_B3_Documentation_05-01/langref/index.html
On 1/21/07, sekar r <[EMAIL PROTECTED]> wrote:
Dear Friends,
i am getting this error on runtime. [NetConnection object must be
connected.].
i have attached image file for error.
plz help me for this.
this my mxml. file.
<?xml version="1.0"?>
<!-- controls\videodisplay\VideoDisplayCamera.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
// Define a variable of type Camera.
import flash.media.Camera;
public var cam:Camera;
[Bindable] private var con:NetConnection;
public var ns:NetStream;
private function initCamera():void {
con = new NetConnection();
con.objectEncoding = flash.net.ObjectEncoding.AMF0;
//if(!con.connected)
con.connect("rtmp://10.21.160.125:1935/liveApp");
//else
//con.close();
var ns:NetStream=new NetStream(con);
// Initialize the variable.
cam = Camera.getCamera();
myVid.attachCamera(cam)
ns.attachCamera(cam);
ns.publish("dhina","live");
}
]]>
</mx:Script>
<mx:VideoDisplay id="myVid"
width="320" height="240"
creationComplete="initCamera();"/>
</mx:Application>
waiting for ur valuable reply
thanks in advance
sekar.
------------------------------
Any questions? Get answers on any topic at Yahoo!
Answers<http://answers.yahoo.com/;_ylc=X3oDMTFvbGNhMGE3BF9TAzM5NjU0NTEwOARfcwMzOTY1NDUxMDMEc2VjA21haWxfdGFnbGluZQRzbGsDbWFpbF90YWcx>.
Try it now.
------------------------------
Looking for earth-friendly autos?
Browse Top Cars by "Green
Rating"<http://autos.yahoo.com/green_center/;_ylc=X3oDMTE4MGw4Z2hlBF9TAzk3MTA3MDc2BHNlYwNtYWlsdGFncwRzbGsDZ3JlZW5jZW50ZXI->at
Yahoo! Autos' Green Center.