As3 - I Simply cannot remove loader child no matter what - actionscript-3

I have loaded an external SWF to my timeline using a common loader method. The SWF is Jwplayer and it is polling a live rtmp stream. Here is the snippet I used to load it successfully.
var c4:Loader = new Loader();
var c4req:URLRequest = new URLRequest("player.swf");
var c4flashvars:URLVariables = new URLVariables();
c4flashvars.streamer = "rtmp://myserver";
c4flashvars.file = "live"
c4req.data = c4flashvars;
c4.load(c4req);
addChild(c4)
Now, the player loads fine. It begins to poll a live stream, too. However, no matter what I try I cannot remove this child from the stage. I have tried the following:
removeChild(c4);
c4.unloadAndStop();
For testing, I am calling these from a timer/event listener/function combo. I traced it to make sure it was being fired, and it is. However the player just sits there on the stage and refuses to leave. Output isn't throwing any errors. I half suspect that because it's polling a live stream that the loader never sees the external SWF as fully loaded. But that's just a hunch.
The overall scope of this little project is to load the player, check for an event, and re-load the player (unload, and reload). If anyone could help me understand this, get past this, or is feeling generous enough to show me the light; I'd appreciate it greatly. I've put a solid day into messing around with this and searching. I'm just not grasping something. Thanks!

Related

How to put music in individual scenes and have it change when i select a new scene

Alright I've managed to make an almost web page style thing in flash. I have all the coding to navigate the pages finished, but now I'm having the issue of when I change pages my main page music continues while the other pages music begins. I.,m unsure of how to code this. can anyone help? also I already have click sound effects going for my buttons and they seem to be working fine. Don't know if that helps at all. I'm also using flash cs6 and don't want to go to cc, because the removal of the bone tool.
To stop a sound, you will need to use a SoundChannel object when you tell the sound to play. Then, with the reference to the SoundChannel, you can stop the sound before you exit the section.
// save this reference for later so you can stop the sound when you want..
var mySoundChannel:SoundChannel = mySound.play(); // Get a sound channel.
// Call this later
mySoundChannel.stop();
Without a SoundChannel to control it, the sound object will do its default behavior, which is to play to completion.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/SoundChannel.html

FLVPlayback VideoEvent.COMPLETE triggers before the video reaches the end, and the video stops playing

import fl.video.*;
var player:FLVPlayback = new FLVPlayback();
addChild(player);
player.skin = "someSkin.swf";
player.source = "http://someDomian/some.flv";
Here's the code. I just load and play some flv from server, and when I test it via Flash (just press ctrl+enter), the video will stop at about 90% of the video and dispatch the COMPLETE event. Any one knows why? Try it again, the time where the video stops is the same, just about 90%.
I searched it, and I tried to change playheadUpdateInterval of player, set totalTime explictly, or set bufferTime longer. All those solutions make no difference.
I tried to load another movie from the same server, same problem. Any chances something wrong with the server?
EDIT:
I sent the swf to someone else, and the video plays as it's supposed to do. Then another guy, and the same result. So, I guess there's something wrong with my settings? Is there some setting will cause this strange action? But when I tried it on my laptop, the video stops unexpectedly. Why this seems to work on everyone's computer except mine?
before CLOSE:
Eventually my colleagues found the strange reason causes this problem, if changing the publish setting to FP10 & 10.1 or FP9, it'll work as we expect. FP10.2 and up, videos on that server seem not have the talent to find their ending. The videos are H.264/AAC, if I convert them to VP60/MP3, all the FP versions will work. Since I can't modify the setting about the codecs, I'll just change the publish setting and leave the codecs thing alone. Although I'm just frustrated by this, if you see this and so lucky that you happen to know the codecs thing why the "early complete" appears, please please tell me.
The problem could be with the .FLV file, sometimes there could be problems while encoding any video file(AVI,MOV,MP4,3GP,WMV) in to .FLV format that results in skipped frames. Try your code with some other .FLV file if that works good then you need to re-encode your FLV file.
You can also try capturing the video Complete Event by tracking the Video Playback Progress.
import fl.video.*;
var player:FLVPlayback = new FLVPlayback();
addChild(player);
player.skin = "someSkin.swf";
player.source = "http://someDomian/some.flv";
addEventListener(Event.ENTER_FRAME, enterFrameHandler);
function enterFrameHandler(event:Event):void {
if(player.playheadPercentage>=99)
{
//On Video Playback Complete Actions here
}
}

How to play two swf files in as3

hai i want play two swf files in my action script project.In this two files one swf file works on the detection face in front of the system.Other swf plays the flv file.when face is detected player must be stooped if not player must be plays the flv file.
I know how to load the swf file but i cant handle the functionality regarding starting and stoping player.
the snippet of code shows how can i load external swf file .and i will explain each line of code in comments
public function videos(view:Sprite)
{
this.box = view;//IT GETS Sprite object from other class because of need to display the player also.
request = new URLRequest("Untitled-1.swf");
currentSWF=new MovieClip();
loader= new Loader();
loader.load(request);
box.addChild(loader);
currentSWF = MovieClip(loader.content);
loader.addEventListener(Event.COMPLETE,loadComplete);
//addChild(loader);
currentSWF.gotoAndPlay(1);//when i put this line of code in comments it plays the external swf also.
}
I hope u understand my doubt .can any one explain how to handle my things .i am new to this action script.please help me
Loaded files automatically play, unless you tell them explicitely not to. You’ll have to listen to the Event.INIT event, and stop the movie there:
loader.AddEventListener(Event.INIT, initLoader);
function initLoader (event:Event)
{
MovieClip(event.currentTarget.content).stop();
}
This will stop the movie before it is attached to the stage, and before it starts playing—so it won’t do that unless you start it again.
Note that you shouldn’t access loader.content in any way before the INIT or COMPLETE events, as it’s very likely that the content isn’t loaded then. As such you should put all your manipulating actions into the COMPLETE event:
box.addChild(loader);
loader.addEventListener(Event.COMPLETE, loadComplete);
function loadComplete (event:Event)
{
// Now it’s safe to access the `content` member:
currentSWF = MovieClip(loader.content);
// Of course this one would play the movie again, so you probably want
// to call that later on a button click or something.
currentSWF.gotoAndPlay(1);
}

unload dynamically loaded swf after displaying it AS3

I am doing a presentation on which I need to use a lot of video clips. I load all these videos dynamically using Loader. I use a code snippet like this:
var req:URLRequest = new URLRequest("video.swf");
var a:Loader = new Loader();
a.load(req);
stage.addChild(a);
a
Now the issue is: When I get to say the 7th one, it starts lagging. I do not know why, but I think it is because everything is loaded to memory. Is there a way I can erase a video from memory after displaying it? Or is there another solution to this?
If you just load a new video each time and add it to the stage, you will have a rather big hierarchy of movies sitting on top of each other; all kept on stage and in memory.
If you keep a reference to the previously loaded movie, you can just remove it from the stage when the 'next' movie is loaded. Haven't tested this properly, but just to give you an idea of what the code might look like:
var oldLoader:Loader = null;
var a:Loader = new Loader();
a.contentLoaderInfo.addEventListener(Event.COMPLETE, loader_complete);
a.load(<your url>);
function loader_complete(e:Event):void {
var newLoader:Loader = e.currentTarget.loader as Loader;
stage.addChild(newLoader);
if(oldLoader != null) {
stage.removeChild(oldLoader);
oldLoader = null;
}
oldLoader = newLoader;
}
I think I found the solution. If you use removeChild, it only stops displaying, but the whole thing is still in memory (cache). So the more you load the videos, the more you fill up the cache. What we need is something that completely clears the cache before loading another video.
I used unloadAndStop() and it seem to have completely done the trick, unless someone has something against it.
Thanks again

Audio of a specific video swf doesn't stop when I load another URLRequest

I am trying to stop the audio of the video swf and I can't get it to stop. Here is my code for loading the file:
var myLoader:Loader= new Loader();
myLoader.x=420;
myLoader.y=200;
// boolean variable set for use below in our function
var screenCheck:Boolean = false;
//These three linces keep stafe elements the same size, so they don't distort
var swfStage:Stage = this.stage;
video_btn.addEventListener(MouseEvent.CLICK,contentvideo);
function contentvideo (event:MouseEvent):void{
myLoader.load(new URLRequest("prevideo.swf"));
addChild(myLoader);
movie_btn.stop();
movie_btn.visible=false;
}
Now I have other functions that load different URLRequest and when they are loading, the audio keeps playing. Do I have to add a line of code to them? I also have an MP3 player and tried SoundMixer.stopAll(). I still need the mp3 player to keep playing.
I'm not familiar with what you're doing but just looking at the code and given the problem you're experiencing I wonder if that
addChild(myLoader);
has anything to do with it. It seems like the kind of thing that could easily create multiple child objects which is why you continue to experience the sound play back. Is there a removeChild[0] option or something?
A shot in the dark I know but I thought I'd offer the possibility anyway.