Friday, October 8, 2010

AS-3/Flex Dictionary weak keys


A sample source code for using a dictionary in AS-3/Flex with weak keys.
When I say new Dictionary(true), after a while all those objects, whose
only references are as the dictionary keys, will be garbage collected.
So, if run the following in debug mode, after a while, output of trace 
will be 0, from 1 initially. 

   1:  <?xml version="1.0"?>
   2:  <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()">
   3:      <mx:Script><![CDATA[
   4:          private var di:Dictionary = new Dictionary(true);
   5:          private function init():void {
   6:             di[new Sprite()] = [1,2,3];
   7:              setTimeout(startTrack,5000);
   8:          }
   9:   
  10:          private function startTrack():void {
  11:             System.gc();
  12:              var count:int = 0;
  13:              for each (var arr:Array in di) {
  14:                  ++count;
  15:              }
  16:              trace("number of elements in dictionary = " +count);
  17:              setTimeout(startTrack,5000);
  18:          }
  19:          ]]></mx:Script>
  20:  </mx:Application>

Sunday, October 3, 2010

php.ini on production

display_errors = Off
error_log = error_log
error_reporting = E_ALL

Wednesday, September 15, 2010

Swftools : An Introduction

What is it : A bundle of tools for finding information/manipulating swfs.
Where do I get it from : Here.

Examples : 
1. Merging two swfs : 
swfcombine.exe -a swf1.swf swf2.swf -o output.swf

2. Dumping information about a swf
swfdump.exe -a some.swf

3. Finding all the exported symbols from a swf : 
swfdump.exe -a some.swf | grep -i exports

Formatting source code for blogging

http://formatmysourcecode.blogspot.com/

JSFL script - iterates over many flas and create swfs for individual symbols


/*
   script tested with Flash CS5,
   should work with older versions.
 */

function universe() {
    var flaPath = "file:///../new_assets/";
    var outputDirPath = "file:///../../../code/trunk/client/game/city/resources/assets/";
    var flaFiles = FLfile.listFolder(flaPath + "*.fla", "files");
    var numFiles = flaFiles.length;
    for (var i = 0; i < numFiles; i++) {
        var flaFilePath = flaPath + flaFiles[i];
        fl.trace("reading "+flaFilePath);
        var doc = fl.openDocument(flaFilePath);
        var items = doc.library.items;
        var iLen = items.length;
        for (var j = 0; j < iLen; j++) {
            var item = items[j];
            if(item.linkageExportForAS) {
                var outputFilePath = outputDirPath+item.linkageClassName+".swf";
                if(fl.fileExists(outputFilePath)) {
                    fl.trace(outputFilePath + " already Exists, you sweet a*s");
                    //return;
                } else {
                    var tmpDoc = fl.createDocument();
                    tmpDoc.addItem({x:0,y:0},item);
                    tmpDoc.exportSWF(outputFilePath);
                    fl.closeDocument(tmpDoc);
                    //fl.trace("exported "+outputFilePath);
                }
            }
        }
        fl.closeDocument(doc);
    }
}
universe();

Blog Archive