How do I dynamically create a Video object in AS2 and add it to a MovieClip?,
I need to dynamically create a Video object in ActionScript 2 and add it to a movie clip. In AS3 I just do this:
var videoViewComp:UIComponent; // created elsewhere videoView = new Video(); videoView.width = 400; videoView.height = 400; this.videoViewComp.addChild(videoView);
Unfortunately, I can’t figure out how to accomplish this in AS2. Video isn’t a child of MovieClip, so attachMovie() doesn’t seem to be getting me anything. I don’t see any equivalent to AS3’s UIComponent.addChild() method either.
Is there any way to dynamically create a Video object in AS2 that actually shows up on the stage?
I potentially need multiple videos at a time though. Is it possible to duplicate that video object?
I think I have another solution working. It’s not optimal, but it fits with some of the things I have to do for other components so it’s not too out of place in the project. Once I get it figured out I’ll post what I did here.
Ok, I’ve got something working.
First, I created a new Library symbol and called it “VideoWrapper”. I then added a single Video object to that with an ID of “video”.
Now, any time I need to dynamically add a Video to my state I can use MovieClip.attachMovie() to add a new copy of the Video object.
To make things easier I wrote a VideoWrapper class that exposes basic UI element handling (setPosition(), setSize(), etc). So when dealing with the Video in regular UI layout code I just use those methods so it looks just like all my other UI elements. When dealing with the video I just access the “video” member of the class.
My actual implementation is a bit more complicated, but that’s the basics of how I got things working. I have a test app that’s playing 2 videos, one from the local camera and one streaming from FMS, and it’s working great.
That’s the answer How do I dynamically create a Video object in AS2 and add it to a MovieClip?, Hope this helps those looking for an answer. Then we suggest to do a search for the next question and find the answer only on our site.
The answers provided above are only to be used to guide the learning process. The questions above are open-ended questions, meaning that many answers are not fixed as above. I hope this article can be useful, Thank you