Your problem is that you don't ever attach the video object to the stage. This line my_vid.attachVideo(video);
does nothing, because MovieClip does not have a method called attachVideo
.
You need to create a video object in your library and add it to the stage. To do this, follow these steps in the IDE:
- Click the arrow at the top right of the libray panel and select
New Video...
from the dropdown.
- In the dialog box, Select the
Video (ActionScript-controlled)
radio button and click OK.
- Drag the newly created video object to the stage and give it an instance name (e.g.
myVideo
).
- Select your video object on the stage and press F8 to create a new symbol from it.
- Set the symbol to type MovieClip, tick the Export for ActionScript checkbox and give an Identifier (e.g.
videoContainer
), then press OK.
- Delete the symbol from the stage, keeping it in the library.
Now you have an item in your library that you can attach with code, that already contains a video object that is ready to work. Your code should be modified as follows, assuming you used the same names as I did above.
//attach the container from the library
my_vid = _root.attachMovie("videoContainer", "my_vid" _root.getNextHighestDepth());
//create a reference to the video object inside the container
var video:Video = my_vid.myVideo;
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
video.attachVideo(ns);
//
// ...
//
ns.play("http://localhost/video.mp4");