Archive for April, 2012

ModuleLoader with progressbar

<mx:ModuleLoader id=”moduleldr” ready=”{moduleProgressBar.visible=false}” height=”100%”
                             width=”100%” applicationDomain=”{ApplicationDomain.currentDomain}”
                             url=”module.swf”
                             loading=”{moduleProgressBar.visible = true}”/>
     

<mx:ProgressBar id=”moduleProgressBar”
                            includeInLayout=”{moduleProgressBar.visible}”
                            horizontalCenter=”0″
                            verticalCenter=”0″
                            source=”{moduleldr}”/>

Leave a comment

Advanceddatagrid with custom tool tip and HTML content

 

<mx:AdvancedDataGrid width=”100%” height=”100%” dataProvider=”{orgData}” id=”iADG”
                         useRollOver=”false” creationComplete=”{onADGCreation();}”>
</mx:AdvancedDataGrid>
  

 
    private function onADGCreation():void
    {
        iADG.addEventListener(ShowToolTipEvent.ROLL_OVER, onIconRollOver);
        iADG.addEventListener(ShowToolTipEvent.ROLL_OUT, onIconRollOut);
        iADG.addEventListener(ShowToolTipEvent.MOUSE_WHEEL, onIconMouseWheel);
    }
    
    private var descToolTipMenu:HTMLToolTipComp = null;
        private var oTimer:Timer;
        private var startSecond:Number;
        private var menuDelayDuration:Number = 500; //delay duration for popup menu
        private var tooltipData:String;

        private function onIconRollOver(event:ShowToolTipEvent):void {
            tooltipData = event.toolTipText ;
            if(tooltipData == null)
                return;
            oTimer.stop();
            startTimer();
        }

        private function onIconRollOut(event:ShowToolTipEvent):void {
            oTimer.stop();
            if(descToolTipMenu==null) return;

            if(!descToolTipMenu.hitTestPoint(event.stageX,event.stageY))
            {
                hideMenu();
            }
        }

        private function onIconMouseWheel(event:ShowToolTipEvent):void {
            hideMenu();
        }

        /**
         * Function: startTimer
         * This function is called from onRollOver function.
         */
        private function startTimer():void
        {
            var oDate:Date = new Date();
            startSecond = oDate.getTime();
            oTimer.start();
        }

        /**
         * Function: checkMouseDelayOnCell
         * This function is the listener for the timer oTimer, called after the delay period of timer.
         * In our case function is called after every 200 miliseconds.
         */
        private function checkMouseDelayOnCell(event:TimerEvent):void
        {
            var oDate:Date = new Date();
            //show the menu if the mouse is over the cell for the duration of menuDelayDuration
            if((oDate.getTime()-startSecond)>menuDelayDuration)    {
                showMenu();
                oTimer.stop();
            }
        }

        public function showMenu():void
        {
            if(descToolTipMenu!=null) return;

            descToolTipMenu = PopUpManager.createPopUp(this,HTMLToolTipComp,false) as HTMLToolTipComp;
            descToolTipMenu.toolTipText = tooltipData ;
            trace(‘current tooltipData[‘+tooltipData+’]’);
            descToolTipMenu.addEventListener(MouseEvent.ROLL_OUT,hideMenuOnRollOut);
            descToolTipMenu.maxHeight = FlexGlobals.topLevelApplication.screen.height ;
            descToolTipMenu.maxWidth = FlexGlobals.topLevelApplication.screen.width ;

            FlexGlobals.topLevelApplication.addEventListener(MouseEvent.MOUSE_MOVE,checkMouseOverMenu);

            var xPos:Number = FlexGlobals.topLevelApplication.mouseX
            var yPos:Number = FlexGlobals.topLevelApplication.mouseY

            descToolTipMenu.addEventListener(FlexEvent.UPDATE_COMPLETE,function(event:FlexEvent)
            {
                if(descToolTipMenu!=null)
                {
                    if(yPos+descToolTipMenu.height>FlexGlobals.topLevelApplication.screen.height)
                    {
                        yPos  = FlexGlobals.topLevelApplication.mouseY – (descToolTipMenu.height+10) ;
                    }
                    if(xPos+descToolTipMenu.width>FlexGlobals.topLevelApplication.screen.width)
                    {
                        xPos = FlexGlobals.topLevelApplication.mouseX – (descToolTipMenu.width+10) ;
                    }

                    descToolTipMenu.move(xPos,yPos);
                }

            });

        }

        private function hideMenu():void
        {
            if(descToolTipMenu!=null)
            {
                PopUpManager.removePopUp(descToolTipMenu);
                descToolTipMenu = null;
            }
        }

        private function hideMenuOnRollOut(event:MouseEvent):void
        {
            if(descToolTipMenu==null) return;

            var nx:Number=event.stageX;
            var ny:Number=event.stageY;

            if((nx<=descToolTipMenu.x || nx>=(descToolTipMenu.x+descToolTipMenu.width) || ny<=descToolTipMenu.y || ny>=(descToolTipMenu.y+descToolTipMenu.height))
                && !this.hitTestPoint(event.stageX,event.stageY))
            {
                hideMenu();
            }
        }

        private function checkMouseOverMenu(event:MouseEvent):void
        {
            if(!this.hitTestPoint(event.stageX,event.stageY))
            {
                hideMenu();
            }
        }
        
        
//——————ShowToolTipEvent.as——————————–//
package com.jpmorgan.myclient.events
{
    import flash.events.Event;
    import flash.events.MouseEvent;

    public class ShowToolTipEvent extends MouseEvent
    {

        public static const ROLL_OVER:String=’mRollOver’;
        public static const ROLL_OUT:String=’mRollOut’;
        public static const MOUSE_WHEEL:String=’mWheel’;

        public var toolTipText:String;

        public function ShowToolTipEvent(type:String, value:String=””, bubbles:Boolean=false, cancelable:Boolean=false)
        {
            this.toolTipText=value;
            super(type, bubbles, cancelable);
        }

        override public function clone():Event
        {
            return new ShowToolTipEvent(type, toolTipText);
        }
    }
}

//————-HTMLToolTipComp.mxml————————-//
<?xml version=”1.0″ encoding=”utf-8″?>
<s:TextArea xmlns:fx=”http://ns.adobe.com/mxml/2009&#8243;
         xmlns:s=”library://ns.adobe.com/flex/spark”
         xmlns:mx=”library://ns.adobe.com/flex/mx”
          borderAlpha=”1″ borderVisible=”true” borderColor=”#000000″
         paddingLeft=”2″ paddingTop=”2″ paddingRight=”2″ paddingBottom=”2″ heightInLines=”{NaN}”
         contentBackgroundAlpha=”1″ contentBackgroundColor=”#ffffff” color=”#000000″
         verticalScrollPolicy=”off” updateComplete=”{onUpdateComplete();}”
        width=”250″>
    

    <fx:Script>
        <![CDATA[
            import flashx.textLayout.conversion.TextConverter;

            [Bindable]private var _toolTipText:String ;

            public function get toolTipText():String
            {
                return _toolTipText;
            }

            public function set toolTipText(value:String):void
            {
                _toolTipText = value;
                showToolTip();
            }

            public function showToolTip():void
            {
                this.textFlow = TextConverter.importToFlow(
                    _toolTipText,
                    TextConverter.TEXT_FIELD_HTML_FORMAT);
            }

            /**need to update */
            protected function onUpdateComplete():void
            {
                this.heightInLines = NaN ;
            }

        ]]>
    </fx:Script>

</s:TextArea>

, , , ,

Leave a comment

Open popup in Module

 var popupComp:IFlexDisplayObject;
 popupComp = PopUpManager.createPopUp(this.parentApplication as DisplayObject,popupComp, true,null, this.moduleFactory);
 PopUpManager.centerPopUp(popupComp);
popupComp.y = (FlexGlobals.topLevelApplication.height – popupComp.height)/2;
popupComp(popupComp).x = ((FlexGlobals.topLevelApplication.width)
                                            – (popupComp(popupComp).width))/2;
    
//set data into popupComp if any through public method setData
popupComp(popupComp).setData(data);

Leave a comment

Remote object call from module with different context

[Bindable]protected var service:mx.rpc.remoting.RemoteObject;           

[Bindable]

private var urlReq:String=URLUtil.getServerNameWithPort(FlexGlobals.topLevelApplication.url) + ‘/’;

[Bindable]
private var urlProtocol:String=URLUtil.getProtocol(FlexGlobals.topLevelApplication.url) + ‘://’;

private function setRPCService(destination:String):void
        {

                 service = new RemoteObject();
                  service.destination = destination ;

                   //service.endpoint

                   service.endpoint= urlProtocol+urlReq+context+’/messagebroker/amf’;

                  //for ex: urlProtocol+urlReq+’homecare/messagebroker/amf’; where homecare is context

                   service.makeObjectsBindable=true;
          }

 

setRPCService(delegate name );               

service.showBusyCursor = true;
 if(service!=null)
  {
         var rpcCall:AsyncToken;
         rpcCall = service.methodname(request parameter);
         rpcCall.addResponder(new mx.rpc.Responder(ResultHandler, FaultHandler));
    }

Leave a comment

Flex rich text editor with toolbar at top instead of bottom

<mx:RichTextEditor id=”richTextEditor” creationComplete=”richTextEditor_creationCompleteHandler(event)”
width=”550″ height=”200″
headerHeight=”0″ />

Script:

protected function richTextEditor_creationCompleteHandler(event:FlexEvent):void

{
richTextEditor.toolbar.removeChild(richTextEditor.linkTextInput)

/* toolbar is in ControlBar, ControlBar is not a direct content
child of the Panel in RichTextEditor. */

richTextEditor.toolbar.parent.removeChild(richTextEditor.toolbar);
controlBarContainer = new HBox();
controlBarContainer.percentWidth = 100;
controlBarContainer.setStyle(‘paddingLeft’, 5);
controlBarContainer.setStyle(‘paddingTop’, 5);
controlBarContainer.setStyle(‘paddingRight’, 5);
controlBarContainer.setStyle(‘paddingBottom’, 5);
controlBarContainer.addChild(richTextEditor.toolbar);
richTextEditor.addChildAt(controlBarContainer, 0);

}

Leave a comment

Flex Mx Rich text editor with height change as per content

 

public const MIN_HEIGHT:uint = 200;
public const DEFAULT_PANEL_HEIGHT:uint = 80

if((richTextEditor.textArea.textHeight + DEFAULT_PANEL_HEIGHT) > richTextEditor.height){
                    richTextEditor.height = richTextEditor.textArea.textHeight + DEFAULT_PANEL_HEIGHT
                }else if(richTextEditor.textArea.textHeight + DEFAULT_PANEL_HEIGHT < MIN_HEIGHT){
                    richTextEditor.height = MIN_HEIGHT;
                }else{
                    richTextEditor.height = richTextEditor.textArea.textHeight + DEFAULT_PANEL_HEIGHT
                }

    <mx:RichTextEditor id=”richTextEditor”
                       width=”550″ height=”200″
                       headerHeight=”0″ change=”richTextEditor_changeHandler(event)”/>

Leave a comment

Spark Combox with case-in-sensitive search

The Spark ComboBox control also searches the item list as the user enters characters into the prompt area. As the user enters characters, the drop-down area of the control opens. It then and scrolls to and highlights the closest match in the item list.

itemMatchingFunction is a callback function used to search the item list as the user enters characters into the prompt area. The function referenced by this property takes an input string and return the index of the items in the data provider that match the input. The items are returned as a Vector.&lt;int&gt; of indices in the data provider.

The callback function must have the following signature:
     * function myMatchingFunction(comboBox:ComboBox, inputText:String):Vector.&lt;int&gt;</pre>
    By default, if an input string of length n is equivalent to the first n characters of an item (ignoring case), then it is a match to that item. For example, ‘aRiz’ is a match to “Arizona” while ‘riz’ is not.</p>

    We have used this function to make case-in-sensitive Combobox.

CaseSensComboBox

<local:CaseSensComboBox caseSens=”true”/>

 

CaseSensComboBox.as 

package
{
    import mx.core.mx_internal;
    
    import spark.components.ComboBox;
    
    public class CaseSensComboBox extends ComboBox
    {
        public function CaseSensComboBox()
        {
            super();
        }
        
        [Bindable]private var _caseSens:Boolean
        public function get caseSens():Boolean
        {
            return _caseSens;
        }

        public function set caseSens(value:Boolean):void
        {
            _caseSens = value;
            if(value)
            {
                this.itemMatchingFunction = caseSensitiveFilterFunc ;
            }
        }
        
        protected function caseSensitiveFilterFunc(comboBox:ComboBox, inputText:String):Vector.<int>
        {
            var matchingItems:Vector.<int>;
            
            if (!dataProvider || dataProvider.length <= 0)
                return matchingItems;
            
            if (textInput.text != “”)
            {
                matchingItems = findMatchingItems(textInput.text);
            }
            else
            {
                // If the input string is empty, then don’t select anything
                this.mx_internal::changeHighlightedSelection(NO_SELECTION);
              }
            
            return matchingItems;
                
        }
        
        // Returns an array of possible values
        private function findMatchingItems(input:String):Vector.<int>
        {
            // For now, just select the first match
            var startIndex:int;
            var stopIndex:int;
            var retVal:int;  
            var retVector:Vector.<int> = new Vector.<int>;
            
            retVal = findStringLoop(input, 0, dataProvider.length);
            
            if (retVal != -1)
                retVector.push(retVal);
            return retVector;
        }
        
        private function findStringLoop(str:String, startIndex:int, stopIndex:int):Number
        {
            // Try to find the item based on the start and stop indices.
            for (startIndex; startIndex != stopIndex; startIndex++)
            {
                var itmStr:String = itemToLabel(dataProvider.getItemAt(startIndex));
                
                itmStr = itmStr.substring(0, str.length);
                if (str == itmStr)
                {
                    return startIndex;
                }
            }
            return -1;
        }

    }
}

 

, ,

1 Comment