Skip to main content
Multoman
Inspiring
March 30, 2023
Answered

Stop playback on a certain frame

  • March 30, 2023
  • 2 replies
  • 1718 views

I upload a certain swf file, it has graphics.On the first frame, Figure 1, on the second frame, figure 2. How do I stop the cyclic playback of these two frames? I tried gotoAndStop(4) but it doesn't work for some reason. Perhaps can just call the desired image after loading the swf file through the class or addChild(), but I do not know how.

 

 

var mcGraphics: MovieClip = new MovieClip(); 
var myLoader: Loader = new Loader(); 
var url: URLRequest = new URLRequest("ExternalSWF.swf");
myLoader.load(url);
mcGraphics.addChild(myLoader);
addChild(mcGraphics);
mcGraphics.x = 10; 
mcGraphics.y = 175;
mcGraphics.gotoAndStop(4) //Does not stop the loop on a specific frame

 

 

Link to the uploaded swf file: https://terabox.com/s/1CX3K5TQQix7qDeQ4PPGY9Q 

 

This topic has been closed for replies.
Correct answer JoãoCésar17023019

Sure.

 

Try this:

import flash.display.LoaderInfo;
import flash.display.MovieClip;
import flash.events.Event;

var myLoader:Loader = new Loader();
var url:URLRequest = new URLRequest("ExternalSWF.swf");

function completeHandler(e:Event):void
{
	var loader:Loader = (e.currentTarget as LoaderInfo).loader;
	var swfRoot:MovieClip = loader.content as MovieClip;
	
	swfRoot.stop();
	e.currentTarget.removeEventListener(e.type, arguments.callee);
}

myLoader.load(url);
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
addChild(myLoader);

2 replies

JoãoCésar17023019
Community Expert
Community Expert
March 30, 2023

Hi.

 

You must first add an event listener of type Event.COMPLETE to the loader's content loader info object to make sure the content is ready to be accessed. Like this:

myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);

 

Also, you're adding a generic MovieClip instance so there won't be frame 4 in it. Maybe what you want is the instance to be of a custom type set in a symbol in the Library.

 

Please check these points and let us know.

 

Regards,

JC

Multoman
MultomanAuthor
Inspiring
March 30, 2023

To be honest, I didn't really understand what the event listener gives. If it's not difficult for you, could you look at my sources. The External SWF.fla file contains two images on different frames, this file is exported to swf and loaded into another swf file (Test.fla). But when the images from External SWF are loaded, the looped playback of all two frames begins, but I need only one (specific) frame to be displayed. How to do it?

https://drive.google.com/drive/folders/1cALM05SNWomyedssU-2dA5T7vw2ysCr8?usp=share_link

kglad
Community Expert
Community Expert
March 30, 2023

try:

 

var mcGraphics: MovieClip = new MovieClip();
var myLoader: Loader = new Loader();

myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeF);
var url: URLRequest = new URLRequest("ExternalSWF.swf");
myLoader.load(url);
mcGraphics.addChild(myLoader);
addChild(mcGraphics);
mcGraphics.x = 10;
mcGraphics.y = 175;

function completeF(e:Event):void{

MovieClip(myLoader.getChildAt(0)).gotoAndStop(3);

}

kglad
Community Expert
Community Expert
March 30, 2023

your gotoAndStop will stop mcGraphics from looping, but won't stop any children (unless they're graphic symbols) from looping including myLoader.

 

you need to reference myLoader or the a child of myLoader.  which loaded timeline is looping?

Multoman
MultomanAuthor
Inspiring
March 30, 2023

My loader is looping 

kglad
Community Expert
Community Expert
March 30, 2023

then apply a stop to it (after loading is completed).