Flash Tracing to flashlog.txt

To confuse an earlier brief post…(“trace() not working in Flash Builder?”), I just wanted to post another quick blurb on how to address an issue I ran into setting up logging from the flash player to flashlog.txt, by means of the mm.cfg file.

As often noted, in order to set up the ability to monitor traced outputs to disk from the flash player, one must:
1. Install the debugger version of the flash player.
2. Create the default named file to which the logging will be sent at (on mac anyway) ~/Library/Preferences/Macromedia/Flash\ Player/Logs/flashlog.txt. You can query online for the proper location for Linux and Windows.
3. On mac, create the mm.cfg file in /Library/Application\ Support/Macromedia
4. Add these lines to the mm.cfg file:
     ErrorReportingEnable=1
     TraceOutputFileEnable=1
5. Restart you machine.

In some cases, however, this does not actually work — that is, nothing gets written to the file, and there is no error to look for. I figured it might be permissions, so changing the permissions for flashlog.txt to 660 (sudo chmod 660 flashlog.txt) fixed the issue. Note that group needs to be set to be readable/writable. After doing a search for the issue online with “chmod” in the search terms, I also found a reference noting that the mm.cfg file needed to have its permissions changed to 755, but I don’t think that is probably necessary. It wasn’t for me.

svndiff2html: Convert SVN Diffs to More Readable HTML

Recently I wanted an easy way to generate diffs from svn that I could easily read — i.e. with some sort of markup. TextMate automatically displays diffs in an attractive manner, and in a manner that makes them much easier to decipher visually. It also allows you to export any code file as html, which is also nice; however, I didn’t want to keep having to open all my diffs in TextMate just for the sake of formatting them. I also wanted to be able to generate them quickly and be able to distribute them as standalone files that could ostensibly be viewed in a web browser.

I did a little research and found a script over at http://www.linuxjournal.com/content/convert-diff-output-colorized-html which was fairly close to what I wanted to do, so I started with that and modified its processing algorithm and css styling to match my TextMate output. After getting that working with static svn diff output files, I added the ability to simply navigate to the desired directory in the command line and invoke the script to output the html formatted diff.

At that point, I decided that there were 2 key comparisons that were important to me generally — svn diff -r HEAD and svn diff -r PREV:HEAD — which output the diff for the local file to the repository version, and the diff for the head as compared to the previous revision. In other words, one compares the stuff on your machine to the repository, and the other can compare what you just committed to what was there before. I added those, and a help command, and that become svndiff2html. I hope this helps someone save some time. Code follows after the break…

Read More »

Pass flashvars from an embedded swf to a loaded swf.

This is somewhat trivial though not entirely intuitive -- passing flashvars from an embedded flash movie to a flash movie that the swf is loading. I was working on some code recently that accomplished this task using one solution that I have seen most often -- by passing the flashvars as query string parameters. In other words:

SwfA.swf is embedded on the page and has the flash var "userName" with the value "Voytek". SwfB.swf is loaded by SwfA.swf, and must utilize the userName variable. Often this will be accomplished by loading SwfB using the URL "SwfB.swf?userName=Voytek". This works just fine for most cases. There are, however some cases where this can be problematic. For example, suppose the site this is to be deployed on is a high traffic site and a caching system is employed to cache the swf files. Depending on the caching server, it may be that files are cached according to their *full* URL, which means that if we now need to load the swf with the userName "Milgrim", we have cached the file a second time referenced by the URL "SwfB.swf?userName=Milgrim". Now deploy this on a site with hundreds of thousands of users, and you might as well not even cache the swf files at all.

Fortunately, it came to my attention that the loaded swf SwfB can access the flashVars just as easily as SwfA, it just so happens that that action of getting the flashVars needs to be made asynchronously. As long as the loaded swf SwfB has already been added to the stage, it can access the flashVars via "stage.loaderInfo.parameters" (rather than accessing the flashVars in the embedded SwfA using "root.loaderInfo.parameters"). In order for this to be possible however, SwfB must be loaded and added to the display list of the stage.

CODE:
  1. package
  2. {   
  3.     import flash.display.Sprite;
  4.     import flash.display.Loader;
  5.     import flash.net.URLRequest;
  6.  
  7.     /**
  8.      * Loads SwfB in the same way a swf usually loads a swf.
  9.      */
  10.     public class SwfA extends Sprite
  11.     {
  12.         public function SwfA()
  13.         {
  14.             var flashVars:Object = root.loaderInfo.parameters;
  15.             var s:String = this + "\n";
  16.             for (var i:String in flashVars) {
  17.                 s += i + " = " + flashVars[i] + "\n";
  18.             }
  19.             trace("Main Client FlashVars:" + s);
  20.            
  21.             var ldr:Loader = new Loader();
  22.             var urlReq:URLRequest = new URLRequest("SwfB.swf");
  23.             ldr.load(urlReq);
  24.             addChild(ldr);
  25.         }
  26.     }
  27. }
  28.  
  29.  
  30. package
  31. {
  32.     import flash.display.Sprite;
  33.     import flash.events.Event;
  34.    
  35.     /**
  36.      * This class is loaded by SwfA and waits until it has been added to the stage
  37.      * in order to obtain the flash vars from the stage.loaderInfo.
  38.      */
  39.     public class SwfB extends Sprite
  40.     {
  41.         public function SwfB()
  42.         {
  43.             addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
  44.         }
  45.        
  46.         private function onAddedToStage(e:Event):void
  47.         {
  48.             var flashVars:Object = stage.loaderInfo.parameters;
  49.             var s:String = this + "\n";
  50.             for (var i:String in flashVars) {
  51.                 s += i + " = " + flashVars[i] + "\n";
  52.             }
  53.             trace("Loaded Swf FlashVars when Added to Stage: " + s);
  54.         }
  55.     }
  56. }

As you can see from the code above, SwfA just loads SwfB just like you would normally do. SwfB just listens for its own ADDED_TO_STAGE event and then grabs the flashVars from the stage's loaderInfo. The only catch is that if the UI build or some other immediate process depends on the flashVars, then you need to make sure and wait for the ADDED_TO_STAGE event in order to proceed.

Posted by way of micro-plains