Blog posts


  • Enable caching from ASP.NET (in IIS7)

    September 01, 2010 | Tags: ASP.NET, Snippet
    Add the following section to your web.config to enable caching (in IIS7):

    <system.webServer>
    <httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
    <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll"/>
    <dynamicTypes>
    <add mimeType="text/*" enabled="true"/>
    <add mimeType="message/*" enabled="true"/>
    <add mimeType="application/javascript" enabled="true"/>
    <add mimeType="*/*" enabled="false"/>
    </dynamicTypes>
    <staticTypes>
    <add mimeType="text/*" enabled="true"/>
    <add mimeType="message/*" enabled="true"/>
    <add mimeType="application/javascript" enabled="true"/>
    <add mimeType="*/*" enabled="false"/>
    </staticTypes>
    </httpCompression>
    <urlCompression doStaticCompression="true" doDynamicCompression="true"/>
    </system.webServer>

    Code taken from How to GZip on ASP.NET and GoDaddy

  • Fix height and overflow hidden problem in Firefox

    August 13, 2010 | Tags:
    The problem
    Older versions of Firefox (for instance 3.0) doesn't handle overflow:hidden very well. It seems to ignore the style if it contains elements (like Flash object) that is larger than the specified height and/or width. It works well in the latest versions of Firefox (3.5+) as well as IE7/8.

    Here's a sample of the problem. The whole 650 pixels high Flash object will be shown, eventhough the div containing it has overflow set to hidden.
    <div>
    <div style="width: 100%; height: 550px; overflow: hidden;">
    <div style="width: 100%;">
    <embed height="650" width="100%" src="/MyFlash.swf" type="application/x-shockwave-flash">
    </div>
    </div>
    </div>

    The solution
    The solution is simple, although not quite logical. If you add a overflow:auto style to a div outside the one you have overflow:hidden it magicly solves the problem:
    <div style="overflow: auto;">
    <div style="width: 100%; height: 550px; overflow: hidden;">
    <div style="width: 100%;">
    <embed height="650" width="100%" src="/MyFlash.swf" type="application/x-shockwave-flash">
    </div>
    </div>
    </div>

  • AS3 TextField alpha problem solved

    August 09, 2010 | Tags: Actionscript, AS3, Troubleshooting, Flash
    Recently I ran into some trouble with a TextField in a Flash/AS3 project. Since the font couldn't be embeded (due to size) the TextField was changed to _sans / "Use device fonts" (_sans and _serif are generic fonts that will use the best match from the clients computer). This introduced a problem, the alpha fades that previously worked with the embeded font suddenly stopped. Setting the alpha value didn't affect the TextField at all.

    The solution to this problem is to set a blend mode on the TextField as for some reason alpha values and device fonts doesn't play well together in the default BlendMode.Normal setting.

    Set the blend mode:
    myTextField.blendMode = BlendMode.LAYER;

    And don't forget the:
    import flash.display.BlendMode;

  • A smarter way to include javascripts and CSS to reduce page load times

    July 26, 2010 | Tags: ASP.NET, SEO, C#
    Published my first article over at CodeProject about reducing load time by combining javascript and stylesheets in one, compressed file.

    Reduce the number of HTTP requests required to render the page, resulting in faster page loads by combining and compressing multiple javascripts into one javascript file and multiple CSS files into one style sheet file.

    Read full article at CodeProject

  • When MouseEnabled fails

    June 16, 2010 | Tags: Actionscript, AS3, Troubleshooting, Flash
    Some problems in Flash can be a real pain sometimes. For instance in the following case.

    Having a sprite that includes another sprite, but only the parent sprite should be able to recieve mouse events. The child sprite would only be used to be painted on in the drawLine function which is called on a regular basis. A simplified version would look something like this:
    public class Tag extends Sprite{
    private var _canvas:Sprite;

    public function Tag() {
    _canvas = new Sprite();
    addChild(_canvas);
    _canvas.mouseEnabled = false;

    addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
    }

    private function onMouseOver(e:MouseEvent):void {
    // Do stuff
    }

    private function drawLine():void{
    var targetX:Number = 120;
    var targetY:Number = 10;

    _canvas.graphics.clear();
    _canvas.graphics.lineStyle(3, 0x888888, 0.75);
    _canvas.graphics.moveTo(0, 0);
    _canvas.graphics.lineTo(targetX, targetY);
    }
    }
    Looks pretty straight forward? _canvas.mouseEnabled is set to false, and that should remove the MouseEvent.MOUSE_OVER from being triggered when the mouse is over the child, right? WRONG!

    Eventhough _canvas.mouseEnabled is disabled it will fire the event as the graphics of _canvas still resides in the parent sprite. The way to solve this is to check which object triggered the event by changing the onMouseOver function to:
      private function onMouseOver(e:MouseEvent):void {
    if (e.target != this)
    return;
    // Do stuff
    }
    Is the target the main sprite? If not bail out of the event handler. Another approach would be to use the hitRect attribute of the main sprite.