Friday, June 25, 2010

Determining Flash Player version in Flex

Flash.system.Capabilities.version and Flash.system.Capabilities.isDebugger are the properties to determine the flash player version

Tuesday, June 22, 2010

Flex name spaces

Controlling method access with name spaces


You could call a different version of calcTax method using the name space soprano with a double colon as shown

tax = Tax.soprano::calcTax();

package com.enron.namespaces {
public namespace soprano=”http://www.enron.com/namespaces”;
}

package com.enron.namespaces {
public namespace regular;
}


package com.enron.tax{
import com.enron.namespaces.*;
public class Tax
{
regular static function calcTax():Number{
return 3500;
}
soprano static function calcTax():Number{
return 1750;
}
}
}

Flex Stage Object

The Stage class represents the main drawing area.

For SWF content running in the browser (in Flash® Player), the Stage represents the entire area where Flash content is shown.

For content running in AIR, each NativeWindow object has a corresponding Stage object.

Reference to Stage object is null until applicationComplete() event - thats where you typically should add any listeners to the stage object

Flex 3 to Flex 4

Features & Migration Guide from Adobe lists them all - pretty useful. Wonder why did not see this earlier

Flash Player 10 in Flex Builder 3.0.2

This is a good post which highlights the steps

 What we essentially gotta do
       a) Install sdk 3.2 & configure it
       b) Remove playerglobal.swc from the existing project build path libraries list and point to  Flash Player 10 playerglobal.swc file as a merged link.

      This file is is in C:\Program Files\Adobe\Flex Builder 3\sdks\3.2.0.3794\frameworks\libs\player\10

Thursday, June 17, 2010

Flex Custom Components

A Great Tutorial  

Singleton in ActionScript!

This is how you'd go about creating a Singleton in ActionScript! Create another class within the same file but outside the package declaration - so that it can only be accessed internally:


package{
    public class Singleton{
        private static var _instance:Singleton=null;
        public function Singleton(e:SingletonEnforcer){
            trace(‘new instance of singleton created’);
        }
        public static function getInstance():Singleton{
            if(_instance==null){
                _instance=new Singleton(new SingletonEnforcer());
            }
            return _instance;
        }
    }
}
//I’m outside the package so I can only be accessed internally
class SingletonEnforcer{
//nothing else required here
}

Wednesday, June 16, 2010

Flex Javascript Integration

Flex Javascript Integration

ExternalInterface defines two especially important static functions:
  • call( functionName:String, ... arguments ) - call a container function
  • addCallback( functionName:String, closure:Function ) - expose a Flex function to the container 
 

Call Browser/JavaScript from ActionScript

// call a JavaScript function defined in the container page
   var result:String = 
      ExternalInterface.call( "doSomethingInJavaScript", arg1, arg2 );
The above ActionScript code could call the below JavaScript code in  the container HTML page:
 
// a JavaScript function in the container HTML page
function doSomethingInJavaScript( arg1, arg2 )
   {
      // do something
      return "results for " + arg1 + " and " + arg2;
   }

Call ActionScript from JavaScript/Browser

public function init():void
   {
      // expose an ActionScript function to the container
      ExternalInterface.addCallback( "doSomethingInActionScript", doSomethingInActionScript );
   }
   
   // function now callable from JavaScript
   public function doSomethingInActionScript( arg1:String, arg2:Number ):String
   {
      return "result";
   }
 
The below JavaScript code can be used to call the exposed ActionScript 
function:
 
// get the Flex application (Flash object)
   var isIE = navigator.appName.indexOf("Microsoft") != -1;
   var flashName = "flashObjectName";
   var flashObject = (isIE) ? parent.Main.window[flashName] : document[flashName];
   
   if( flashObject )
   {
      // call the Flex application (Flash object)
      flashObject.doSomethingInActionScript( "arg1", 2 );
   }
 

 

 


Tuesday, June 15, 2010

Flex Gotchas

1) Construtors cannot be private / protected / internal - They can only be public - use of public keyword is optional.

      a) Create a javascript function which makes use of xmlHTTPRequest object


             xmlHttpRequest.open("GET","http://serverName/URL",true); //true = sync, false = async

      b) Make the javascript function call which will invoke  this javascript function from within Flex using ExternalInterface class

               ExternalInterfac.call(javaScriptFunctionDefinitionStringWhichMakesTheXmlHTTPRequestCall); 

3) When should you use state change[ and transition] vs when should you replace the UI

You use state change when you have to just add or remove a few components in the view and controls pretty much remain the same.

You replace the UI when you have a completely new set of controls 

4) What happens when you removeChild() - parent reference is set to null

5)  When you set a specific height and width of a component, Flex does not call the measure() method, even if you explicitly call the invalidateSize() method. Flex calls the measure() method only if the explicitWidth property or the explicitHeight property of the component is NaN.



 



.