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

Stop playback on a certain frame

Contributor ,
Mar 30, 2023 Mar 30, 2023

Copy link to clipboard

Copied

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

Views

830

Translate

Translate

Report

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
...

Votes

Translate

Translate
Community Expert ,
Mar 30, 2023 Mar 30, 2023

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

My loader is looping 

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

myLoader.gotoAndStop(3)

Returns an error

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

}

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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()

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

i updated the code (several times).

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Great. Thank you very much

 

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

You're welcome!

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

@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

 

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Hi.

 

Sorry for the late reply.

 

Did you find the solution?

 

Please let us know.

 

Regards,

JC

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Hello, no

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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