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

Unload SWF and Return to a frame in the Initial SWF

Explorer ,
Sep 23, 2018 Sep 23, 2018

Hello, I used to use Flash quite often years ago when this was easily done - I guess back in the AS2 days. I have found this difficult to do in AS3. I have created the same presentation in 4 languages. I first created the original English version then duplicated the file to make the conversions. The presentation starts with an initial file titled "Engine360" - Buttons animate in and the time line stops. Viewer then selects which language they prefer by clicking the appropriate button. Let's say the viewer selects "English" The English button directs the play head to a label where the buttons animate off stage, the play head stops on a frame that loads "360English.swf". The code on this frame I used is:

var EnglishLoader:Loader = new Loader();

var url:URLRequest = new URLRequest("360English.swf");

EnglishLoader.load(url);

addChild(EnglishLoader);

This works perfectly, the play head in the initial file "Engine360" is stopped on a blank frame while the viewer watches the loaded "360English.swf". My problem is the viewer needs to be able to select a "Reset" button. The "Reset" button needs to unload the "360English.swf" and return the play head back to the initial "Engine360" say "frame 5" where they can once again select the preferred language. This was once easy, now it's not, but I have spent very little time learning AS3. Any help with this would be immensely appreciated!! I thank you in advance.

Oh, not sure if this is important but this will be published AIR 26.0 for Desktop with Windows installer.

1.2K
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 , Sep 24, 2018 Sep 24, 2018

Hi.

Use the unloadAndStop function from the Loader class.

Here is a sample where there are two frames in the main timeline. The first one contains two buttons (englishButton and portugueseButton) to change the language.

In the second frame, the SWFs are actually loaded and there is a reset button.

AS3 code:

Frame 1

import flash.events.MouseEvent;

import flash.display.Loader;

import flash.net.URLRequest;

var swf:String;

var loader:Loader;

function changeLanguage(e:MouseEvent):void

{

     swf = e.currentTarget

...
Translate
Community Expert ,
Sep 24, 2018 Sep 24, 2018

Hi.

Use the unloadAndStop function from the Loader class.

Here is a sample where there are two frames in the main timeline. The first one contains two buttons (englishButton and portugueseButton) to change the language.

In the second frame, the SWFs are actually loaded and there is a reset button.

AS3 code:

Frame 1

import flash.events.MouseEvent;

import flash.display.Loader;

import flash.net.URLRequest;

var swf:String;

var loader:Loader;

function changeLanguage(e:MouseEvent):void

{

     swf = e.currentTarget.name.replace("Button", "") + ".swf";

     gotoAndStop(2);

}

function reset(e:MouseEvent):void

{

     loader.unloadAndStop(true);

     removeChild(loader);

     loader = null;

     gotoAndStop(1);

}

stop();

englishButton.addEventListener(MouseEvent.CLICK, changeLanguage);

portugueseButton.addEventListener(MouseEvent.CLICK, changeLanguage);

Frame 2

loader = new Loader();

loader.load(new URLRequest(swf));

addChild(loader);

resetButton.addEventListener(MouseEvent.CLICK, reset);

FLA download:

animate_cc_as3_unload_swf.zip - Google Drive

I hope this helps.

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
Explorer ,
Sep 24, 2018 Sep 24, 2018

Thank for the response and examples, however I need the reset button to be contained in the loaded swf, not the initial swf. The reason is I created moving stage animations in Cinema 4D, exported them as a series of .ai files, then imported them into animate as vectors. Basically when the viewer clicks a button in the loaded "360English.swf" the camera moves as if it is inside much larger stage. The camera moves from main stage to a stage above, stage left, right, etc... depending on the viewers selection. If the reset button is viewable in the initial swf it would be very strange as the camera moves and the reset button doesn't. I attached a video of the camera movement inside the loaded "360English.swf" The reset button will be available at the beginning only.

Basically I need the loaded "360English.swf" to unload itself by clicking reset and return the initial play head to frame 5 in "Engine360"

The video is the swf I need to unload. The initial swf is not present in this video.

Thank you for your help, it is greatly appreciated.

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 ,
Sep 24, 2018 Sep 24, 2018

No problem.

Just move the reset buttons to each external SWF and paste this code in each of them (in the main timeline):

import flash.display.MovieClip;

resetButton.addEventListener(MouseEvent.CLICK, (parent.parent as MovieClip).reset);

The reset function declaration must stay in the main SWF.

Regards,

JC

P.S.: amazing presentation.

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
Explorer ,
Sep 24, 2018 Sep 24, 2018

Thank you! Thank you for the amazingly fast help! Client ended up wanting the "Language Reset" present at all moments of the presentation so I ended up using the code example in your first response.

I made a small transparent Flag button at top of stage. Its not that distracting from the presentation.

I love the code, works very well! Thank you 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
Explorer ,
Sep 24, 2018 Sep 24, 2018

I have one other question you probably know the answer to. How do I stop a video from loading full screen? I have it positioned center stage. The stage is 1920x1080, video is 1280x720. I want it to load in center of stage, no full screen. Thank you!

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 ,
Sep 24, 2018 Sep 24, 2018

Excellent! You're welcome!

How are you loading your video? Are you using a component?

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
Explorer ,
Sep 24, 2018 Sep 24, 2018

I solved the video issue I was having. Everything is working perfectly. Thanks again!

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
Explorer ,
Sep 29, 2018 Sep 29, 2018

Hello, I have another issue. Is it possible to add a preloader animation to this? When the user makes a language selection the swf being loaded is rather large. It basically goes blank for about 5 seconds. I am using the initial script you posted. I can't thank you enough for your help!

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 ,
Oct 01, 2018 Oct 01, 2018

Hi.

Sure.

Here is an updated version of the previous sample:

animate_cc_as3_unload_swf_3.zip - Google Drive

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
Explorer ,
Oct 01, 2018 Oct 01, 2018

I don't see an fla in the download. Thank you

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 ,
Oct 01, 2018 Oct 01, 2018

Oops! Sorry about that!

I've just updated the 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
Explorer ,
Oct 01, 2018 Oct 01, 2018

Getting this on test

Scene 1, Layer 'Actions', Frame 6, Line 1, Column 21 1046: Type was not found or was not a compile-time constant: LoaderAnimation.

Scene 1, Layer 'Actions', Frame 6, Line 1, Column 43 1180: Call to a possibly undefined method LoaderAnimation.

Do I need to add "complete" anywhere?

Sorry for being confused, thanks.

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 ,
Oct 01, 2018 Oct 01, 2018

Please make sure to copy the LoaderAnimation symbol that is in the Library of my FLA to yours.

This is because an instance of this class will be added dynamically at runtime.

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
Explorer ,
Oct 01, 2018 Oct 01, 2018

Sorry I missed that, its working perfectly. Thank you for the help with this, I will make my deadline because of you. People like you make this multi-media lifestyle much, much better!

Thank you!

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 ,
Oct 01, 2018 Oct 01, 2018
LATEST

Thanks a lot!

I do appreciate.

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