0 Replies Latest reply on Oct 25, 2010 12:25 PM by revmischa

    Creating AIR native window popups for 1/60th of a second

    revmischa

      I am trying to create a simple desktop AIR application for testing the usefulness of subliminal messaging. My requirement is that I display an image overlaid on top of all other windows for as short as possible a time so as to be unnoticable. Given that pretty much all LCD monitors now are 60hz, I believe the smallest amount of time I can show it for is 1/60th of a second.

      While I'm not really sure how to time what I have now, it seems to be rather noticeable and probably a good deal longer. I was wondering if there would be a way to show an image for 1/60th of a second (or less if possible) in a way that a user wouldn't notice it running (consciously).

       

      Here's what I am doing right now. Maybe there is some more efficient way to do this, like keeping the window invisible and then showing, forcing a draw, and then immediately hiding again? If I try to make the window invisible I get an undefined error. I'm using code based off of a sample AIR popup window application:

       

      public class PopupMessageWindow extends NativeWindow

      {

      public var timeToLive:uint;

      private static const stockWidth:int = 250;

      private var manager:PopupDisplayManager;

      private const format:TextFormat = new TextFormat("arial",14,0);

       

      public function PopupMessageWindow(message:String, manager:PopupDisplayManager):void{

      this.manager = manager;

       

      var options:NativeWindowInitOptions = new NativeWindowInitOptions();

      options.type = NativeWindowType.LIGHTWEIGHT;

      options.systemChrome = NativeWindowSystemChrome.NONE;

      //options.transparent = true;

      super(options);

       

      stage.addEventListener(MouseEvent.MOUSE_DOWN,onClick);

      stage.align = StageAlign.TOP_LEFT;

      stage.scaleMode = StageScaleMode.NO_SCALE;

       

      manager.addEventListener(PopupDisplayManager.LIFE_TICK,lifeTick,false,0,true);

      width = PopupMessageWindow.stockWidth;

       

      var textDisplay:TextField = new TextField();

      textDisplay.text = message;

      textDisplay.wordWrap = true;

      textDisplay.setTextFormat(format);

      stage.addChild(textDisplay);

      textDisplay.x = 5;

      textDisplay.y = 5;

      textDisplay.width = width - 10;

      height = textDisplay.textHeight + 10;

       

      draw();

      alwaysInFront = true;

      close();

      }

       

      private function onClick(event:MouseEvent):void{

      close();

      }

       

      public function lifeTick(event:Event):void{

      timeToLive--;

      if(timeToLive < 1){

      //close();

      }

      }

       

      public override function close():void{

      manager.removeEventListener(PopupDisplayManager.LIFE_TICK,lifeTick,false);

      super.close();

      }

       

      private function draw():void{

      var background:Sprite = new Sprite();

      with(background.graphics){

      lineStyle(1);

      beginFill(0xddffdd,.9);

      drawRoundRect(2,2,width-4,height-4,8,8);

      endFill();

      }

      stage.addChildAt(background, 0);

      }

      }