Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Stop playback on a certain frame

Contributor ,
Mar 30, 2023 Mar 30, 2023

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 

 

TOPICS
ActionScript , Code
2.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Mar 30, 2023 Mar 30, 2023

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.addEven
...
Translate
Community Expert ,
Mar 30, 2023 Mar 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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Mar 30, 2023 Mar 30, 2023

My loader is looping 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 30, 2023 Mar 30, 2023

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Mar 30, 2023 Mar 30, 2023
myLoader.gotoAndStop(3)

Returns an error

1061: Accessing the possibly undefined gotoAndStop method via a static flash.display type link:Loader.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 30, 2023 Mar 30, 2023

did you use a complete event to ensure loading was completed?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 30, 2023 Mar 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Mar 30, 2023 Mar 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 30, 2023 Mar 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);

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Mar 30, 2023 Mar 30, 2023

Gives the following error:

TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::Loader@36d687e4ea1 to flash.display.MovieClip.
at Test_fla::MainTimeline/completeF()

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 30, 2023 Mar 30, 2023

i updated the code (several times).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 30, 2023 Mar 30, 2023

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);
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Mar 30, 2023 Mar 30, 2023

Great. Thank you very much

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 30, 2023 Mar 30, 2023

You're welcome!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Apr 03, 2023 Apr 03, 2023

@JoãoCésarTell me what to do if I need to add (myLoader) to a simple button. When I hover over the button, all frames are played inside it and the original position (the first frame) is reset. How can I fix this problem ? (myLoader) is also placed in movieclip, since the button will contain not only (myLoader), but also other images.

 

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

var mcGraphicsButton: MovieClip = new MovieClip();
var button: SimpleButton = new SimpleButton(); 
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.gotoAndStop(2)
	e.currentTarget.removeEventListener(e.type, arguments.callee);
}

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

function makeGraphics() {
	var rect: Shape = new Shape();
	rect.graphics.beginFill(0x00ff00)
	rect.graphics.drawRoundRect(0, 0, 200, 200, 12, 12);
	return rect;
}
mcGraphicsButton.addChild(makeGraphics());
mcGraphicsButton.addChild(myLoader);

button.upState = mcGraphicsButton;
button.overState = mcGraphicsButton;
button.downState = mcGraphicsButton;
button.hitTestState = mcGraphicsButton;
addChild(button)

 

 

bandicam 2023-04-03 22-31-56-145_1.gif

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 06, 2023 Apr 06, 2023

Hi.

 

Sorry for the late reply.

 

Did you find the solution?

 

Please let us know.

 

Regards,

JC

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Apr 06, 2023 Apr 06, 2023

Hello, no

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 10, 2023 Apr 10, 2023

Hi again.

 

I think it would be more efficient if you inserted the drawings into the button states instead of inserting the loader.

And why do you need the green rectangle?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Apr 10, 2023 Apr 10, 2023
LATEST

Hello. A how can i insert a picture into the button ? Do I need to convert the loader to an image? The green rectangle is the background for the drawing, the background may be a different color. I painted it green just for an example.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines