Monday, July 30, 2012

Flex - Combobox as Dropdownlist

Creating CustomComboBoxDropDownList – Use to switch from ComboBox to DropDownList and v/s.
I was wondering how developer can use same component to switch from ComboBox to DropDownList and v/s. so I did some workaround to find out the solution, Here we go –
Q. - How to user combobox as dropdownlist by using user defined custom property.
Steps to create custom component. Consider file name as below: -
Class Name: - CustomComboBoxDropDownList.MXML

Step 1: - Create custom component which extend combobox
Ex: -
s:ComboBox xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" width="100%" height="100%"
change="onComBoxIndexChange(event)" creationComplete="setPromptText()"
skinClass="skins.SkinComboBox ">

     
     
       fx:Script>

      import mx.controls.Alert;
                 
      import skins.SkinDropDownList;
                 
      import spark.components.DropDownList;
      import spark.core.IDisplayText;
      import spark.events.IndexChangeEvent;
                 
      private var promptText:String;
                 
      public var _useAsDropDown:Boolean = false;
                 
      private function setPromptText():void
      {
        promptText = this.prompt;
        setUserSelectedSkin();
      }
                 
      public function set useAsDropDown(value:Boolean):void
      {
         _useAsDropDown = value;
      }
                 
      public function get useAsDropDown():Boolean
      {
          return _useAsDropDown;
      }
                 
      private function setUserSelectedSkin():void
      {
         if(_useAsDropDown)
         {
          this.setStyle("skinClass", SkinDropDownList);
         }
      }
                 
      private function onComBoxIndexChange(event:IndexChangeEvent):void{
        if (event.newIndex < 0){
          if(this.textInput)
           this.textInput.text = promptText;
           Alert.show("Typed item is not present in list","Warning");
        }
      }
]]>
fx:Script>
s:ComboBox>

Step 2: - Create combobox skin named as SkinComboBox.

Step 3: - Create DropDownList skin as SkinDropDownList
      In SkinDropDownList skin Class remove Label and replace TextInput.

Ex. as below: -

id="textInput" borderAlpha="0" borderVisible="false"
mouseEnabled="false" mouseChildren="false" editable="false" selectable="false" left="7" right="30" top="2" bottom="2" width="75" verticalCenter="1" contentBackgroundAlpha="0" color="0x000000" />

Solution: -
You have to change skin at run time on condition. Here I have created useAsDropDown property which will define which component you want to show i.e. ComboBox or DropDownList.

Thursday, February 2, 2012

Flex - Crossdomain

Hi All,

Crossdomain is one of the points where developer has to suffer a lot. To make it simple I have some important points below, which will make developer bit relax on crossdomain concept.

To check for authentication on flex side: -

If Flex application want to communicate with server side, below code need to be added on Flex side.

Security.allowDomain("*");

Above lines will check for the permission form public domain.


What is Security.allowDomain: -

The primary purpose of calling the Security.allowDomain() method is to grant permission for SWF files in an outside domain to script the SWF file, calling the Security.allowDomain() method.
Specifying an IP address as a parameter to the Security.allowDomain(ipAdd) method does not permit access by all parties that originate at the specified IP address. Instead, it permits access only by a party that contains the specified IP address as its URL, rather than a domain name that maps to that IP address. For example, if the domain name www.example.com maps to the IP address 192.0.34.166, a call to Security.allowDomain("192.0.34.166") does not grant access to www.example.com.
You can pass the "*" wildcard to the Security.allowDomain() method to allow access from all domains. Because it grants permission for SWF files from all domains to script the calling SWF file, use the "*" wildcard with care.


Flash Player restriction for lower version than 9.0.124: -

Flash Player version 9.0.124: It no longer allows you to send custom HTTP headers to a remote host. Example: a SWF from “Domain A” wants to send custom HTTP headers in a GET/POST request to “Domain B”. By default, starting with Flash Player 9.0.124 this won't work!"

As we are using both web service and HTTP service (method="GET") call to get data from server

crossdomain.xml format: -

File Name should be: - crossdomain.xml








How swf behaves with crossdomain file: -

When a SWF file attempts to access data from another domain, Flash Player automatically attempts to load a policy file from that domain. If the domain of the SWF file that is attempting to access the data is included in the policy file, the data is automatically accessible.
By default, policy files must be named crossdomain.xml and must reside in the root directory of the server.
A policy file affects access only to the particular server on which it resides.

Why “*”:-
Wildcard domains are indicated by either a single asterisk (*), which matches all domains and all IP addresses.

Where do the policy files need to reside XML web server
Policy files must be named crossdomain.xml and must reside in the root directory of the server.

One more important point: -
Check Firewall Security [internal and external access to port] which block user to access port.

Thanks for reading post…….