Externally loaded MovieClip won't Stop() - actionscript-3

I have externally loaded a .swf asset that is an animated character with a timeline. I load the clip as follows:
m_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, LoaderComplete);
m_loader.load(new URLRequest("test.swf"));
private function LoaderComplete(e:Event):void
{
var movie:MovieClip = m_loader.content as MovieClip;
stage.addChild(movie);
movie.gotoAndStop(1);
}
But the animation just keeps on playing. Stop() also does not work. I'm not sure what I am doing wrong here, I feel like it has to do with being an externally loaded .swf file.

If you have library objects that are on the stage but have their own timeline, you'll need to make sure that all of them are stopped. What happens when you publish the movie.swf - does it keep running?

Related

Remove SWF file after loading a Different SWF file using "Loader" in Flash (AS3)

I am trying to load multiple swf files. But the problem is that whenever I load them (back and forth; vice-versa), my file keeps on slowing down. I looked a solution from the internet, such as using "unload" and "removeChild" but I can't get a clear solution and I don't know where to put it. Any help is very much appreciated..Here's my code on how I load my swfs:
MainMenu.swf:
//***************CLICK GALLERY*********************//
Gallery_btn.addEventListener(MouseEvent.CLICK, Gallery);
function Gallery(event:MouseEvent):void{
var ldr1:Loader=new Loader();
ldr1.load(new URLRequest("Gallery.swf"));
addChild(ldr1);
}
Gallery.swf:
//***************CLICK QUIT******************//
Quit_btn.addEventListener(MouseEvent.CLICK, Quit);
function Quit(event:MouseEvent):void{
var ldr1:Loader=new Loader();
ldr1.load(new URLRequest("MainMenu.swf"));
addChild(ldr1);
}
You need to use removeChild and remove every listener. You can unload swf by calling unload on your loader or unloadAndStop.
You can read this article for more information.
UnloadAndStop from Adobe
Unload SWF

When the game of an external swf is finished, remove the external swf

I am creating a series of mini games and animations and plan on bringing them all into one flash file. Each of the games need to disappear when the player has finished them. I don't know what to put into the section in the external swfs when the game is done. I currently just have a trace ("finished").
In my main swf you should click start and a game swf appears and when you are finished it, it should disappear.
I have looked up tutorials and they something about accessing variables in the external swfs but I got nowhere with them.
in place of trace("finished");, dispatch something like a complete event:
dispatchEvent(new Event(Event.COMPLETE));
Then listen for that event in the container swf and respond appropriately.
Here is an example for the host (parent) swf:
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loadDone, false,0,true);
loader.load(new URLRequest("temp2.swf"));
function loadDone(e:Event){
trace("CONTENT LOADED");
addChild(loader.content);
loader.content.addEventListener(Event.COMPLETE,go,false,0,true); //listen on the capture phase (third parameter true) if you're complete event is NOT on the main timeline of your child swf
}
function go(e:Event):void {
trace("Content is all done");
removeChild(loader.content);
loader.unloadAndStop(); //tries to free the app of all memory used by the loaded swf
loader = null;
}
Another way, is in place of trace("finished"), you could have the child swf remove itself (as per a comment on the question). I would consider this a less desirable solution (though more encapsulated) as it lessens re usability and will likely still leave the swf in memory:
stop();
if(this.parent){
this.parent.removeChild(this);
}

AS3: add event listeners to loaded AS2 SWF

What I am trying to do is - simply load an external SWF into my AS3 code.
I then want to show it on my stage - and be able to catch the 'ROLL_OVER', 'ROLL_OUT' and 'MOUSE_CLICK' events that happen with the SWF, meaning - I want to know when the user hovers over the loaded SWF and when he clicks on it.
If I load an external AS3 SWF - it all works fine, and I can trace the events successfully.
If I load an external AS2 SWF - in some types of AS2 banners I can catch the events, and in some - I can't.
It is important to note that I cannot control the loaded SWFs and I cannot code them in a different manner.
The way I load the external SWFs is like this:
.
var loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onLoaded);
loader.load(new URLRequest(externalSwfURL));
function onLoaded(evt:Event):void
{
// The reason I don't create the MovieClip like this is because I need to support
// both AS2 and AS3 that will be loaded, and loaded AS2 cannot be casted to 'MovieClip'
//var mc:MovieClip = MovieClip(evt.target.content);
// This method allows me to load both external AS2 and AS3 SWF files
var mc:MovieClip = new MovieClip();
mc.addChild(loader);
// Add the events that I want to track
mc.addEventListener(MouseEvent.ROLL_OVER , onMouseEnterSWF);
mc.addEventListener(MouseEvent.ROLL_OUT , onMouseLeaveSWF);
mc.addEventListener(MouseEvent.CLICK , onMouseClickSWF);
mc.x = 100;
mc.y = 100;
stage.addChild(mc);
}
.
What I have found out is that if the loaded AS2 SWF has a transparent button on top of it (a lot of them have that) - then the mouse events aren't fired back up to my AS3 code ! They are somehow 'swallowed' inside the loaded AS2 SWF and not bubbled up.
If I try to load an AS3 SWF that has a transparent button as the top layer - it works, and still bubbles up the mouse events to my AS3 code.
Can anyone tell me why this happens ?
PS - if I load an AS2 SWF that doesn't have a transparent button as a top layer - than the mouse events ARE bubbled up to my AS3 code.
Here is a link to an AS2 SWF file that has the 'transparent button' that blocks the events from bubbling up to the AS3 code:
link to AS2 SWF
ActionScript 2 runs in a different virtual machine and is not compatible with ActionScript 3. Communication between the two SWFs ist not even not easy, but works only with a local connection. ActionScript 2 also doesn't have an event system so this would be the second part to take care of.
-> it can't work as you expect it to.

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);
}

ActionScript3 Extrenal Preloader Won't Play Movie Clip

I'm sure this a simple problem and I'm overlooking something obvious.
I have an external pre-loading SWF that contains nothing but a movie clip (loader_graphic) on one layer, in the first (and only) frame; and a loading script on another layer, in the first frame. The movie clip is just a simple loop animation with no progress indicators. If I don't include the script, it works great.
The script loads the external SWF, and by itself, it works just as it should.
When I combine the two, I get the first frame of the movie clip, and then it freezes until the external SWF is fully loaded. Once it's loaded, it plays one time and stops. I'm somewhat new to AS3, and I know that preloading is one of the conventions that has changed, so I probably don't have it coded properly:
loader_graphic.play();
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.ProgressEvent;
var l:Loader = new Loader();
l.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loop);
l.contentLoaderInfo.addEventListener(Event.COMPLETE, done);
l.load(new URLRequest("external.swf"));
function loop(e:ProgressEvent):void
{
var perc:Number = e.bytesLoaded / e.bytesTotal;
}
function done(e:Event):void
{
loader_graphic.stop();
addChild(l);
}
Any help is appreciated.
It turns out that the preloader was playing all along. It was just stalled because the main SWF was overloading the Flash player.
The main SWF it was loading included an F4V video being streamed from a standard web server, and it was too much for the player to handle all at once. I embedded the video, instead, and it all worked perfectly.