|
-
Externally loaded .flv still on screen when stopped
I have successfully loaded an external looping video and stopped it using a keypress function that closes the ns and nc. However a still of the last viewed frame of my video is frozen on the screen and when I go to any other frame in the timeline it covers over the image in the new frame. Also when I go back to the timeline frame with the video a new instance of that video plays but you can still see the image of the old video on the screen. How do I totally remove the video?
Here is my code to call the video: No problems here I think.
---------------------
stop();
//Defining the video to import
var vid:Video = new Video(1280,720);
addChild(vid);
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
vid.attachNetStream(ns);
var listener:Object = new Object();
listener.onMetaData = function(evt:Object):void {};
ns.client = listener;
ns.play("video1.flv");
//loop
//function playStatus(event:NetStatusEvent):void
//{
//if (event.info.code == "NetStream.Play.Stop")
//{
//ns.seek(0);
//}
//}
//ns.addEventListener(NetStatusEvent.NET_STATUS, playStatus);
Here is my function to close the video
-------------------
function unloadSwitch(){
if(ns){
ns.close();
nc.close();
}
}
-------------------
Thanks for your help in advance
-
Senior Member
If you have frames in the timeline you need to delete the video object.
- The right of the People to create Flash movies shall not be infringed. -
-
So since I used the addChild(vid) to bring in the video what code would I use to remove the vid?
-
Senior Member
- The right of the People to create Flash movies shall not be infringed. -
-
Thanks for the reply, that worked great . I can play the video and when I go to another frame it completely unloads and removes. However when I go back to play that frame I get this error:
---------------
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display: isplayObjectContainer/removeChild()
at DPD_bug02_fla::MainTimeline/unloadSwitch()
at DPD_bug02_fla::MainTimeline/onStageKeyDown()
---------------
I'm pretty new to flash (obviously) and not familiar with what this means. I have 7 keyframes in my timeline.
Frame 01 has code in which I define what keypress goes to what frame and unload the video:
----------------------
stop();
//Event listener for Keyboard press
stage.addEventListener (KeyboardEvent.KEY_DOWN, onStageKeyDown, false, 0, true);
//Function to see what key was pressed
function onStageKeyDown (e:KeyboardEvent) {
//Preset Keycodes//
if (e.keyCode == 72)
{
unloadSwitch();
gotoAndStop ("home");
}
if (e.keyCode == 66)
{
unloadSwitch();
gotoAndStop ("black");
}
if (e.keyCode == 71)
{
unloadSwitch();
gotoAndStop ("green");
}
if (e.keyCode == 70)
{
unloadSwitch();
gotoAndStop ("desktop2");
}
if (e.keyCode == 68)
{
unloadSwitch();
gotoAndStop ("desktop1");
}
if (e.keyCode == 49)
{
unloadSwitch();
gotoAndStop ("cue01");
}
if (e.keyCode == 50)
{
unloadSwitch();
gotoAndStop ("cue02");
}
}
function unloadSwitch(){
trace('video_unloaded');
if(ns){
removeChild(vid);
ns.close();
nc.close();
}
if(ns2){
removeChild(vid2);
ns2.close();
nc2.close();
}
}
---------------------------------
Frame 3-5 Just have images and Frame 6 and 7 have the video code:
stop();
//Defining the video to import
var vid:Video = new Video(1280,720);
addChild(vid);
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
vid.attachNetStream(ns);
var listener:Object = new Object();
listener.onMetaData = function(evt:Object):void {};
ns.client = listener;
ns.play("video1.flv");
//loop
function playStatus(event:NetStatusEvent):void
{
if (event.info.code == "NetStream.Play.Stop")
{
ns.seek(0);
}
}
ns.addEventListener(NetStatusEvent.NET_STATUS, playStatus);
-
Senior Member
this should avoid the error:
if(vid != null)
{
removeChild(vid);
}
- The right of the People to create Flash movies shall not be infringed. -
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|