AS2: No video with netstream, just audio

2.6k Views Asked by At

So I'm having a problem with AS2 when loading a netstream video.

my_vid = _root.createEmptyMovieClip("my_vid", _root.getNextHighestDepth());
var video:Video = new Video();
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
video.attachVideo(ns);
my_vid.attachVideo(video);

and later 
ns.play("http://localhost/video.mp4");

I can actually listen to the audio in background but for some reason i can't see any picture. I tried with a video only without a movieclip, and the other way around and keep listening only to audio.

I'm definitely doing something wrong but what?

1

There are 1 best solutions below

1
On

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:

  1. Click the arrow at the top right of the libray panel and select New Video... from the dropdown.
  2. In the dialog box, Select the Video (ActionScript-controlled) radio button and click OK.
  3. Drag the newly created video object to the stage and give it an instance name (e.g. myVideo).
  4. Select your video object on the stage and press F8 to create a new symbol from it.
  5. Set the symbol to type MovieClip, tick the Export for ActionScript checkbox and give an Identifier (e.g. videoContainer), then press OK.
  6. 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");