Thursday 2 September 2010

Logical XOR

Flash doesn't have a logical XOR, only a bitwise XOR. That means that you can only do bitwise operations, or swap number and attribute the result to a variable.

Well I needed a Boolean XOR, like the one with Truth Tables that we know from logical programming. Well this little function takes care of this:

public function xor(lhs:Boolean, rhs:Boolean):Boolean {


return !( lhs && rhs ) && ( lhs || rhs );

}



Cheers,
Leonel

Wednesday 1 September 2010

Fullscreen... and back

To get your stage into full screen you must do in two steps. The first is to set your stage display state in ActionScript. The other is to allow this scaling in the HTML page.

First of all, place a MovieClip in the stage, by code, or directly in the stage. Give it a instance name.
I will cal mine: fullScr

Associate with fullScr an event listener to catch a mouse event to execute the full screen:

fullScr.addEventListener(MouseEvent.CLICK, handleMouseClick);

Write the handleMouseClick function that will set the display state of the stage. This function will detect the current display state, and change it accordingly. If the display state is NORMAL, it will set it to FULLSCREEN. Otherwise it will be NORMAL again:


private function handleMouseClick(me:MouseEvent):void
{
   if (stage.displayState == StageDisplayState.NORMAL) {
     try{
        stage.displayState=StageDisplayState.FULL_SCREEN;
     }
     catch (e:SecurityError){
        //if you don't complete STEP TWO below, you will get this SecurityError
       trace("an error has occured. please modify the html file to allow    
       fullscreen mode");
     }
   }else {
  try{
       stage.displayState=StageDisplayState.NORMAL;
     }
     catch (e:SecurityError){
       //if you don't complete STEP TWO below, you will get this SecurityError
       trace("an error has occured. please modify the html file to allow 
       fullscreen mode");
     }
  }
}

If you have a video component like FLVPlayback, when you hit fullscreen, this component will take over the screen because it is on top of everything else. To prevent this add this line:

myPlayer.fullScreenTakeOver=false;

Cheers,
Leonel