Copy link to clipboard
Copied
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.
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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 !
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
Excellent! You're welcome!
How are you loading your video? Are you using a component?
Copy link to clipboard
Copied
I solved the video issue I was having. Everything is working perfectly. Thanks again!
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
Hi.
Sure.
Here is an updated version of the previous sample:
animate_cc_as3_unload_swf_3.zip - Google Drive
Regards,
JC
Copy link to clipboard
Copied
I don't see an fla in the download. Thank you
Copy link to clipboard
Copied
Oops! Sorry about that!
I've just updated the link.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
Thanks a lot!
I do appreciate.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now