A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: Help lowering swf filesize

  1. #1
    Member
    Join Date
    Jul 2008
    Posts
    94

    Help lowering swf filesize

    Hiya, I have a flex app which is literally just a tree control, but its coming out as half a megabyte big. Can anyone help me make it smaller?

    I think it has something to do with font embedding, but the resources I've found haven't helped too much, as I am a complete flex idiot.

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="initVars()" height="400" width="150" backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#D4F5FB, #D4F5FB]" themeColor="#FFFFFF" borderStyle="none" borderColor="#FFFFFF">
    
    	<mx:Script>
    		<![CDATA[
    	//treeXML.send();
    			[Bindable]
    			public var userid:String;
    			[Bindable]
    			public var userURL:String;
    			//userid
    			private function initVars():void 
    			{
            		userid = Application.application.parameters.userid;       		
            		//userURL = "http://url/tree/xml.php?userid=" + 2;
            		userURL = "http://url/tree/xml.php?userid=" + userid;
            		workloop();
            		treeXML.send();        		
         		}
    
    			private var loopcnt:int = 0;
    
    			private function workloop():void
    			{
    			  if( loopcnt++ > 1)
    			     expandTree();  
    			   else
    			   {
    			      // do some work here, call work functions etc 
    			      loopcnt++
    			     setTimeout( workloop, 1000);  // call this function again after 1 sec until loopcnt = 10
    			    }
    			// 
    			}
    
    			private function expandTree():void
    			{
    				for (var i:int = 0; i < mytree.dataProvider.length; i ++)
    				{
    					mytree.expandChildrenOf(mytree.dataProvider[i], true)
    				}
    			}
    
    		    [Bindable]
                [Embed("../assets/fclose.png")]
                private var myFolderClosedIcon:Class;
    
                [Bindable]
                [Embed("../assets/fopen.png")]
                private var myFolderOpenIcon:Class;
    
                [Bindable]
                [Embed("../assets/fclose.png")]
                private var myDefaultLeafIcon:Class;
    		    
    		    [Bindable]
    		    public var selectedNode:XML;
    		
    		    // Event handler for the Tree control change event.
    		    public function treeChanged(event:Event):void {
    		        selectedNode=Tree(event.target).selectedItem as XML;
    		        var url:String = selectedNode.@nodeURL;
    				var request:URLRequest = new URLRequest(url);
    				try {
      					navigateToURL(request, '_self'); // second argument is target
    				} catch (e:Error) {
      					trace("Error occurred!");
    				}
    		    }	
    		]]>
    	</mx:Script>
    	
    	<mx:HTTPService id="treeXML" url="{userURL}" resultFormat="e4x" />
    	<mx:Tree
    	horizontalScrollPolicy="on"  
    	id="mytree" 
    	dataProvider="{treeXML.lastResult.dir}" 
    	labelField="@name" 
    	change="treeChanged(event)"
    	top="0" 
    	left="0" 
    	right="0" 
    	bottom="0"
    	borderStyle="none" backgroundColor="#D4F5FB"
    	defaultLeafIcon="{myDefaultLeafIcon}"
       	folderOpenIcon="{myFolderOpenIcon}"
    	folderClosedIcon="{myFolderClosedIcon}" 
    	creationComplete="expandTree()" 
    	dragEnabled="true" 
    	dropEnabled="true"
    	showRoot="true"
    	/> 
    </mx:Application>
    Thanks for any help/advice,

    Dave

  2. #2
    supervillain gerbick's Avatar
    Join Date
    Jul 2000
    Location
    undecided.
    Posts
    18,979
    Your library includes do not seem to be that big - your class includes/imports that is - but the *.png's - how big in total are they?

    Otherwise, your code looks real straightforward and doesn't seem to as for a lot to be compiled into it.

    [ Hello ] | [ gerbick ] | [ Ω ]

  3. #3
    Member
    Join Date
    Jul 2008
    Posts
    94
    Thanks for having a look, I should have mentioned the png's - I'd say the same thing as you, but they are 306 BYTES, 307b and 444b, so about 1 and half kb in total!

  4. #4
    supervillain gerbick's Avatar
    Join Date
    Jul 2000
    Location
    undecided.
    Posts
    18,979
    Even full font embedding shouldn't really hit you for more than 180kb in most cases - and that's being a bit heavy there - that's all Latin chars. I've embedded fonts explicitly and not really had a problem with most fonts that were OpenType - some TrueTypes can get huge because they included uppercase, lowercase, bold... all Latin characters basically.

    If you wish to test your font embedding, remove it from the portions that would use it - but to be honest, you're not even using something like Degrafa. So I don't think you would get that much of a file boost removing it.

    I can take a look at this closer tomorrow; but I'll assume that you have no other *.mxml or *.as that's in the same /src folder right? Clean your build process and then produce a final build and see if that reduces the size. Test builds are never fully optimized.

    [ Hello ] | [ gerbick ] | [ Ω ]

  5. #5
    Member
    Join Date
    Jul 2008
    Posts
    94
    Thank you so much for taking an interest in this!

    Hope this isn't rude or asking too much - but would you mind compiling it on your computer? I think it is something happening when I build it, but everything I change here seems to do nothing... I have attached the two pictures that it requires, I think everything else is pretty standard.

    If it works and builds, you won't see anything, as it needs a session variable embedded in the html page - not to mention a php page - but I only need the swf!!

    I'll definitely fix it, but I'd be interested to know if it is my code or something else.

    Thanks again, no problem if you don't have time or are just generally not interested!

    Dave
    Attached Images Attached Images

  6. #6
    supervillain gerbick's Avatar
    Join Date
    Jul 2000
    Location
    undecided.
    Posts
    18,979
    I built and exported a release build to 328kb
    Attached Images Attached Images

    [ Hello ] | [ gerbick ] | [ Ω ]

  7. #7
    Member
    Join Date
    Jul 2008
    Posts
    94
    I just hit that filesize yesterday!

    thank you so much for doing that buddy, and for your general support!!

  8. #8
    supervillain gerbick's Avatar
    Join Date
    Jul 2000
    Location
    undecided.
    Posts
    18,979
    This sounds crazy, but if I were you, drop any unnecessary comments and spacing. You'll save about... 5k in total, but I did get it slightly closer to 320kb after toying around and changing the spacing a bit...

    Just odd that it's so big. I know that Flex can be a bit bloated, but this is... three components at best.

    [ Hello ] | [ gerbick ] | [ Ω ]

  9. #9
    Member
    Join Date
    Jul 2008
    Posts
    94
    Yeah I know what you mean, but I just compiled an adobe example, about 20 lines of .mxml and it came out at about 263kb. Must just be a big component!!

    Thanks so much for all your input, i really appreciate it. I'll definitely take your advice on the cleaning up.

    Thanks again, Dave

  10. #10
    Senior Member Gohloum's Avatar
    Join Date
    Aug 2002
    Location
    Florida
    Posts
    185
    It's your RSL's and lack of using the optimize tool on your final .swf. I dont have docs or examples handy but here is what will shrink it down.

    1 - RSL (Runtime Shared Libraries). You want to build your main file to use the framework and rpc libraries from an external location. This should shave over 200K off your file. Granted a new visitor may have to load those files, but if they have visited a site using RSLs, chances are they are cached and this will speed up load time.

    2 - Optimize tool. Once you build a Release Build, there is still some debug code and other misc stuff in the .swf that can be removed. You run the Optimize commmand tool against your .swf and it will shave off more file size from it.

    Just google RSL's for Flex and the Flex Optimize tool.

    Hope this helps!
    The Early Bird may get the worm, but the second mouse to the trap gets the cheese...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center