My .fla is about 600mb big due to enormous amount of library objects.
I have 15.500 objects in library and most of them are images. This is probably bad practice, but my client required to have these images inside of it instead of loading them dynamically from some external source.
I have already reduced the size of the images as much as possible while still maintaining good quality.
I'm publishing for Flash Player, and already tried different versions.
Basicly my app is fairly simple test paper app, populating 20 test papers with simple multiple choise questions. Each test paper has 150 questions divided into 4 sections, and each question contains 1 question image and 4 answer images to choose from. After user picks his/her answer, these image instances are being deleted and new ones are being created.
I've heard that there's magical limit of 16.000 for everything like instances and so on, so it should stay right about under it as the code itself is quite simple and there's not many other instances after these images.
Besides my ugly file size, I'm also pushing all these images from library into arrays in a loop:
(linkage names are for example "Paper1_Chem_Q1_C.jpg", and "_X" marks the correct answer - that's why I unshift that one)
var sectionLengths:Array = [40,40,45,25];
var prefixes:Array = ["Phys","Chem","Maths","Eng_Reas"];
var prefixes2:Array = ["A","B","C","D"];
for(var p:int = 0; p<20; p++){ //test papers loop
for(var s:int = 0; s<4; s++){ //sections loop
var fillQArray:Array = this["tp"+(p+1)+"section"+(s+1)+"questions"];
var fillAArray:Array = this["tp"+(p+1)+"section"+(s+1)+"answers"];
for(var q:int = 0; q<sectionLengths[s]; q++){ //question loop
if(ApplicationDomain.currentDomain.hasDefinition(String("Paper"+(p+1)+"_"+prefixes[s]+"_Q"+(q+1)))){
fillQArray.push(getDefinitionByName("Paper"+(p+1)+"_"+prefixes[s]+"_Q"+(q+1)) as Class);
var qa:Array = new Array();
for(var a:int = 0; a<4; a++){ //answers loop
if(ApplicationDomain.currentDomain.hasDefinition(String("Paper"+(p+1)+"_"+prefixes[s]+"_Q"+(q+1)+"_"+prefixes2[a]))){
qa.push(getDefinitionByName("Paper"+(p+1)+"_"+prefixes[s]+"_Q"+(q+1)+"_"+prefixes2[a]));
}else if(ApplicationDomain.currentDomain.hasDefinition(String("Paper"+(p+1)+"_"+prefixes[s]+"_Q"+(q+1)+"_"+prefixes2[a]+"_X"))){
qa.unshift(getDefinitionByName("Paper"+(p+1)+"_"+prefixes[s]+"_Q"+(q+1)+"_"+prefixes2[a]+"_X"));
}
}
fillAArray.push(qa);
}
}
}
}
This loop surely does the job, but takes some time to run. Also, I predefine a LOT of arrays before it, so can this be another potential issue?
During development I've tested everything with few test papers, and it all worked like a charm, but now when I imported all the rest of the images, it gets stuck on publish. I left it to publish for the whole night, but now at morning it's once again stuck and I have to kill Flash process in order to quit it.
I have also increased memory amount from jvm.ini already to 2048m, so it doesn't give anymore the warning dialog regarding to too small JVM memory.
All suggestions are more than welcome.
I finally got it working, thanks to Vesper!
Here's detailed instructions for Flash Professional CC (so detailed becouse this was all new to me, and I spent almost 2 days for this failing multiple times):
Step 1 - Publish SWC:
Create empty .fla and import your images to library. Select all the
images and open properties with mouse2 button. At ActionScript tab
select Export for ActionScript. Make sure that also Export in frame 1 is activated.
Define a Classname for your project at Properties panel, for example: images_swc.
Go to Publish Settings and publish only SWC.
Notes:
In my case I had to create 3 SWC files becouse of the amount of images (15000+).
While adding/removing large amount of images to/from library, and while publishing a SWC, Flash Professional stopped responding and it looked like a crash, but in 30-60mins it succesfully finished!
When it was over an hour in "not responding" -state, I killed Flash process and tried with smaller amount of images.
First I created my "empty" .fla by removing everything but images from my main project, but somehow it didn't export correct images during SWC publish. But after I Saved As.. my image project, it worked like a charm.
Always when Flash notified about low JVM memory, I doubled the memory value in jvm.ini and started over. (Had eventually 4096m.)
Step 2 - Use SWC in your main project:
File -> Publish Settings -> Advanced ActionScript 3.0 Settings (wrench -icon at top-right-corner) -> Library path tab -> Click Browse to SWC file, locate your SWC and click OK.
Create empty .as file and type every image classname into it. Idea here is to mention all the images from SWC so that compiler understands that you want to include them in your main project. e.g:
package {
public class Assets {
image_1;
image_2;
image_3;
}
}
In your main project, include Assets.as and your SWC-file(s):
import Assets;
import images_swc;
Refer to your images with:
getDefinitionByName("image_1")
Final notes:
If you forget your "SWC classname", change the extension of your SWC file to .zip, open it, and you'll find your classname and other details from the xml file inside of it.
To get filenames of large amount of images for your .as file (assuming you have same classnames and filenames for your images), you can use windows command prompt and "dir /s > filename.txt" -command to gether filenames into txt-file. Myself I used free version of Directory List & Print which also finds files from subfolders, pasted the file list into Assets.as and used Find & Replace functionality in Flash to replace ".jpg" with ";".
So, I had over 15000 images, turned them into 3 SWC files = 15-20 megs per SWC, and my final .swf was around 55 megs - and it was compiled in couple minutes, which makes this pretty perfect solution for my project.
#Vesper, thanks again! :)
Related
So I want to know if there is a way to add textures in an already created .pack file instead of repacking all the textures again with the new additions.
Atlases support paging, basically, you append a new page to the atlas.
Add a blank line to the pack file and then start the next atlas. Either pack the next page and copy/paste the file to the end or write it manually.
This line is where it starts a new page:
https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/graphics/g2d/TextureAtlas.java#L110
What I like to do during development is repacking all raw images each time I run the project. This off course can be commented out to safe time but for my personal projects packing rarely exceeds a couple of seconds. So as long as you do not change existing filenames all changes and additions will be pushed trough.
I usually create a separate folder within the project folder called images. Here I put all my images, if I want to have my packs categorized I create additional folders to pack separately. Then in the desktop module I add the following lines:
Settings settings = new Settings();
//settings.XXXXXX change packer settings to your preferences.
//Since I set my working folder to android/assets I need to go down 2
//folders to get into the root of the project and access images.
//Likewise, for output I already start in my assets folder.
//So setting the path might differ depending on your working/asset folder.
TexturePacker.process(settings, "../../images/tileset01", "tilesets", "tileset01");
In the above scenario I have put all my separate images for tileset01 in the folder project\images\tileset01 and they will be packed into project\android\assets\tilesets as tileset01.png and tileset01.pack.
I'm working on creating flash games using actionscript 3, i'm trying to open a Flixel project with FlashDevelop but i can't find a way to do it, i cerated a new project and put the files inside but nothing it seems to work, this is the link for the project on Github :
https://github.com/monday8am/BigHeadFootball_FLA
Although 'nothing seems to work' is a bit of a vague description, you might want to consider the following:
1. When you have put all the files in the FlashDevelop project folder (so that means merging the existing src folder with the one from the project etc.) have you set the Document class correctly?
2. If you've followed step 1 and try to run it, what kind of errors come up? If it can't find certain classes or assets you might have to move these.
Basically, it should be possible to open the project with FD once you've set the correct Document class and merged the two projects correctly.
I have a file upload component written in ActionScript 3. The component is using the FileReferenceList.browse() to let the user select the files to upload. This method accepts an array of FileFilter objects to narrow down the selectable file types.
Until this time I passed only one FileFilter element in the array - if I passed any. This worked well for years without any problem. But recently I ran into a situation when I thought I understand why this method takes an array of FileFilters. Probably I was wrong...
I have a service which designed (and used) to present visual material mainly (images), but it can deal with non-visual files too like .xls, .doc, .zip, etc. This means in practice that my admin will upload almost only images (99%) to this service BUT sometimes (s)he will upload 1-2 .xls, .doc or .zip, etc.
So from this point I didn't want to really block files outside the (image) filter. Just tried to "show" my admin user that the preferred files are images here, but at the end of the day (s)he must be able to upload any file type.
So, I did this:
var fileReferenceList : FileReferenceList = new FileReferenceList();
var imgFilefilter : FileFilter = new FileFilter("Images", "*.jpg;*.jpeg;*.gif;*.png");
var allFilesFilter : FileFilter = new FileFilter("All files", "*");
fileReferenceList.browse([imgFileFilter, allFilesFilter]);
This worked well - on Windows. When the file browser window comes up my user sees the image files only. But (s)he can switch to "all files" view and upload other files too.
But now it turned out my Mac users are screwed this way... The file browser window doesn't offer the possibility to switch to "All files" view, so they can not upload non-image files :-) arghhhh!
I'm wondering what could be the best solution for the problem I tried to describe above? A trivial solution could be that for Mac users I skip the FileFilter stuff entirely. But it is not the way I would prefer... OR did I missed something? Is it possible to somehow "convince" Mac file browser window to offer the possibility let my admin choose between the filters like Win file selector does?
I downloaded some code earlier from a tutorial and I need to look it over so as I can see where I am going wrong, yet I am struggling with it. In theory, it should have rather a lot of code, 100 lines or so at least, but when I open it I get:
import TBG07a;
var mygame:TBG07a = new TBG07a(this);
and I'm unsure why. I checked the Actionscript (3.0) properties, nothing hidden, I checked everything I can think of but it's 1 frame, 1 scene, 1 layer.... I can't think where any of the rest of the code would appear. It is of course a .fla file and it works completely when I run it.
I'm probab;y missing something stupid here but I'm unsure, can anybody help at all?
Ta.
John.
John, check out the directory where *.fla file is located, if there are any .as files in that folder? If no files found, then check fla's Library pannel, if any movieclips there have "AS Linkage" property filled (if so, try editing those movieclips). Also you may check out "File"->"ActionScript Settings"->"Source Path" list (by default it consists only one "." folder).
by using flash cs5 with a huge internal image library (over 300+ small png-files) i need more than 90seconds for each compiling action! the as code is pretty well, also my computer (quad core, 4gigs of ram). i've found out, that by exporting the files to "stage 1" (bild 1 in my screenshot) flash starts to hang around, but i don't know why...
.
how to speed this process up ?
__________________________________________________________________________________________________________________________________________
__________________________________________________________________________________________________________________________________________
my solution did not work:
so i've played around and ended up creating *.as-files for each single bitmap, but the speed-result is the same (maybe 10% - 15% faster than before)...
package
{
import flash.display.*;
dynamic public class MY_BITMAP_NAME extends BitmapData
{
public function MY_BITMAP_NAME(width:int = 500, height:int = 135)
{
super(width, height);
return;
}
}
}
i can not work fast enough to debug my project files :-(
The solution would be to move your assets inside a precompiled SWC library that you will only recompile when they change.
Building the library:
create a new FLA and move in your Bitmaps,
each image needs to have a linkage class name and be exported in first frame; you don't have to create an AS class, Flash will generate them,
in the publish settings, "Flash" tab, check "Export SWC",
this SWC library will be published in the same location as the SWF; in CS4-5 you can't prevent the SWF creation.
Using the library
in your main FLA publish settings, "Flash" tab, open the Advanced Actionscript 3 settings dialog,
in the "Library path" tab you can add the assets library SWC; make sure the "Link Type" is "Merged into code",
SWC content will be available in your main FLA as if they were in the library.
It is worth noting that:
you must instantiate these assets by code (ie. new AssetName): they will not appear in your main FLA's Library panel and you can not drop them on the timeline,
only assets you explicitly reference in your code will be available at run time; if you are using getDefinitionByName() you must still import the assets somewhere in your code. For instance you can declare an Array containing all your assets classes (ex: var assets:Array = [AssetClass1, AssetClass2,...]).
if these 300+ images don't change too often, you could create a second .fla, where you only put the images in the library. Then you publish that .fla as a swc file (You can set this in the publish settings).
And you use that swc in your original .fla (that now has no images anymore), where you have your code (using the swc means, in the publish settings -> actionscript settings, you set the swc as a library reference).
This way, Flash only has to compile your code and simply takes the already compiled images from the swc. It then should compile much faster.
ctrl+enter, that will compile all things in library and the AS code.
most situation that use just change little things, and then compile it.
it would waste much time that no need to waste.
you can export some thing that would not always be changed to SWC file, and to to publish setting,
add SWC file into your Fla. or move you Fla project to Flash build, compile use less time more than in flash ide.