Cannot free memory of or unload flash swf - actionscript-3

I'm using Adobe Animate CC with AS3. I'm having the following problem with my project (which has a lot of animation in it and hence is quite heavy)
There are 4 swf files which are in the same folder. The first one is like a blank container which loads the second swf automatically upon run. The second one has got a few buttons in it along with some animation. When the animation gets over, there is a button that loads the third swf. Now this 3rd swf has got a next button to load the next swf. The 4th swf has got back button to load the previous swf. The 3rd swf has in turn a home button that loads the 2nd swf.
Now, the problem is that when the next button is pressed, say on 2nd swf, not only should the 3rd swf open but the 2nd swf should get unloaded and the memory occupied by it should be freed. And same with the 3rd and the 4th swf.
However, the unloaded swf should open again when the back button is clicked.
If anyone could provide a link to or code for back button and load-unload, that'd be greatly appreciated.

I think it is much easier to load them all at once and then switch their visibility/attachment to the stage. However, if they are indeed too heavy to reside in the memory at once, you need a little trick to load them into a separate ApplicationDomain so they could be removed without anything left behind.
import flash.display.Loader;
import flash.net.URLRequest;
import flash.system.LoaderContext;
import flash.system.ApplicationDomain;
var aLoader:Loader = new Loader;
// Loading an SWF so it can be fully unloaded.
aLoader.load(new URLRequest("external.swf"), new LoaderContext(false, new ApplicationDomain));
// Unloading the loaded SWF.
aLoader.unloadAndStop(true);

Related

Adobe Flash CS6 gives me an error when importing image sequence to timeline

It will import the first 10 images but anything after that just won't work and the workspace turns completely blank and I need to restart Flash CS6.
How ever if I import the images in a new project, nothing wrong happens. I tried to export it as a swf and import that to the original swf file but it didn't work. It just imported the images that I was able to import earlier.
Is there any solution with AS3 where I can load another swf and close the current one opened? Or any other solution to importing the images.
Thanks!
but anything after that just won't work and the workspace turns completely blank and I need to restart Flash CS6
I assume you export big images, so you have out of memory in your development environment.
Do you need Image Gallery? It isn't hard to create simple image gallery, and of course you don't need to import images to the library and publish with application.
So I found out how to load a swf file, but how would I unload it/get rid of it?
If you decided to wrap your images in swf. By referencing Loader that you have used for loading swf, you could unload child SWF — Loader.unloadAndStop

Only the loader images are being exported in frame 1 but the loader still only shows up at 100%

As the title says, the file loads correctly but the loading screen only flashes up at the end.
The only thing being exported in frame 1 is the loader image, and that is extremely small.
Is it possible that there's a queue of things being loaded and the loader image is at the bottom of that queue? Since that was one of the last things added to the project
If your preloader only shows up after the file has loaded, this means that you still have other objects being linked onto Frame 1. Flash is very picky about this, and it's easy for things to be yanked onto Frame 1 regardless of your settings. When you compile, Flash builds a dependency graph to determine what items are needed on each frame. If it thinks an asset is needed earlier than the export frame setting, it will ignore the setting and push the asset onto that frame. In particular, any class that your document class directly references will be automatically yanked onto frame 1.
Checking "Generate size report" in File, Publish Settings, Flash can help you see how much data is being exported onto Frame 1. Here are some tips to ensure that everything is linked onto the proper frame:
In Publish Settings, Flash, ActionScript Settings, make sure that "Export frame for classes" is set to 2 or higher.
Ensure that library symbols say "Export on frame 2" in their linkage properties. Older versions of Flash may export them on frame 1, regardless of the class export frame. In this case, you'll have to do the oldschool method of unchecking the "Export on frame 1" option, and manually dragging these symbols onto the timeline on frame 2.
Do not directly reference classes from your document class or on the main timeline. The Document class and all the assets it references are always placed on frame 1. Anytime you do var f : MyClass; in your document class or on the root timeline, then you are referencing MyClass, and Flash will automatically yank it onto frame 1.
To avoid directly referencing your main app class in your preloader, you want to instantiate it indirectly, using something like this:
var gameClass : Class = flash.utils.getDefinitionByName("Game") as Class;
var game : Sprite = new gameClass();
In this case, your Preloader becomes the document class, and indirectly creates the Game class when the SWF has loaded. This avoids any direct references to Game and its content.

As3 Preloader (Blank until 100%)

I have an FLA file with two frames. On the first frame I have nothing but a textfield and some code to do the preloading. After it is done preloading it does gotoAndStop(2)
On frame 1 I have:
stop();
stage.scaleMode = StageScaleMode.SHOW_ALL;
//Import the required assets
import flash.display.*;
//Stop the playhead while loading occurs
this.stop();
//Create a listener to call the loading function as the movie loads;
this.loaderInfo.addEventListener(ProgressEvent.PROGRESS, PL_LOADING);
this.loaderInfo.addEventListener(Event.COMPLETE, PL_FINISH);
function PL_LOADING(event:ProgressEvent):void
{
var pcent:Number = event.bytesLoaded / event.bytesTotal * 100;
//Display the % loaded in textfield
txt.text = int(pcent) + "%";
//If the movie is fully loaded, kick to the next frame on the main timeline
}
function PL_FINISH(event:Event):void
{
removeChild(txt);
gotoAndStop(2);
}
On frame 2 I have nothing except:
var game:Game = new Game();
addChild(game);
In my publisher settings I have export to frame 2.
My problem is that the preloader won't display until 100%. Does anyone know why?
P.S. For testing I put a large image file on the stage in frame 2 and the result is the same.
This normally happens if you haven't deselected "Export in frame 1" in each of the library symbols that you are exporting for ActionScript.
You'll need to make sure that you create reference to these objects (so that ActionScript can access them) by placing them onto the stage in frame 2 (out of sight).
What's happening is that all of the symbols are being loaded before the preloader itself has loaded.
If this isn't the issue, then please provide some code so I can better assess your issue.
Have you tried putting something static on frame one? Just because there is a preloader, that doesn't mean that your swf will be displaying at all...
I know that I had one swf once which simply took a minute to actually get the Flex preloader to even show up because of network latency. It could be that your swf isn't displaying until 90% of it has already loaded.
I´m dealing with similar problems, and there is something i found out: my antivirus contains a kind of "browser protection" feature, which sort of checks all files in advance before it allows the browser to actually display them. If this antivirus feature has not been installed on the system, the preloader works beautifully. I´ve checked some other web-sites with flash content, and they also behave "wrong" under these circumstances. Now, some people seem to have found a way to stop the antivirus from messing around, but i don´t know how they do it... not yet...

Preloader in as3 using preloader sample provided in cs5

I am working on a project in which i want to add preloader and for that i have used the sample preloader provided in cs5 (in sample files). i have moved(from another fla) all my code to second frame and all library content to current fla's library.
Now the problem is that the size of first frame is now 182kb (the size of library content)
which is only 8kb when i have not added my library content in current fla's library.
And due to this when i test the movie the first frame(preloader) is not shown up until the 182 kb is loaded and immediately after that second frame is shown up.
here my question is how can i load library contents in second frame ?
i am having a large number of library content which is expected to increase in future.
here are two snapshot:
the library:
testing the movie:
you can see in second snapshot the size of first frame is 182kb.
Please provide a good solution for this problem.
Thanks !
Assets which have not linkage load until the frame they first appear, so if you move all your assets to the second (or later) frame, you could have code in the first frame that executes before all the other assets (in frame two or later) finish loading.
You could create your preloader in another fla. This new fla's only job would be to load/preload your main fla, so your preloader's fla size would be very small.
In such case, you wouldn't have to move your library content to the second frame of your main fla, quite the opposite actually.

Adding an as2 swf to the stage in an as3 swf

I have a menu control (as2), that is completely self-contained and doesn't rely on any interaction with the parent (as3). The menu control does load an external xml file that is in the same directory as the swf.
The menu control works fine when I run it on its own. But when I import it into the Library of my as3 fla, add it the stage and run it, it just sits and does nothing.
I can see the images that are part of the control, which leads me to believe it can't load the xml, but I'm not sure.
Does anyone have any ideas about:
Loading an as2 swf into and as3 swf where they don't need to interact
Loading an external file into an swf inside of another swf
Have you tried with flash.net.Loader or if you are going for a Flex app: SWFLoader?