Home Tutorials Forums Articles Blogs Movies Library Employment Press

<< Prev 5 |

SelectionManager

/**
* @author: Eric Feminella
* @url: http://www.ericfeminella.com
* @copyright: (c)2004 - 2006 code.ericfeminella.com
*/

import mx.controls.TextArea;



class com.displays.SelectionManager
{
        
        public static var caretIndex:Number;
        public static var mouseEvent:Boolean;
        public static var lastIndex:Number = 0;
        
        
        public function SelectionManager()
        {
                this.initUserEvent();
        }
        
        
        private function initUserEvent():Void
        {
                var mouseListenerObject:Object = {};
                mouseListenerObject.onMouseUp = SelectionManager.onSetFocus;
                Mouse.addListener(mouseListenerObject);
        }
        
        
        public static function onSetFocus():Void
        {
                if (Selection.getCaretIndex() != -1)
                {
                        SelectionManager.caretIndex = Selection.getCaretIndex();
                        SelectionManager.mouseEvent = true;
                        SelectionManager.lastIndex = 0;
                }
        }
        
        
        public function insertAtSelectedIndex(stringToInsert:String, selectedTextArea:TextArea):String
        {
                
                var index:Number = this.getIndex(stringToInsert.length);
                
                var originalString:String = selectedTextArea.text;
                var originalStringLength:Number = originalString.length;
                
                var selectionStart:String = originalString.substring(0, index);
                
                
                var selectionEnd:String = originalString.substring(index, originalStringLength);
                
                var newString:String = selectionStart + " "  + stringToInsert + " " + selectionEnd;
                
                return newString;
        }
        
        
        private function getIndex(stringToInsertLength:Number):Number
        {
                
                if (SelectionManager.mouseEvent)
                {
                        var index:Number = SelectionManager.caretIndex;
                        SelectionManager.lastIndex = index + stringToInsertLength + 2;
                }
                else
                {
                        var index:Number = SelectionManager.lastIndex + stringToInsertLength;
                        SelectionManager.lastIndex = index + 2;
                }
                
                SelectionManager.mouseEvent = false;
                
                return index;
        }
}

Posted by: Eric Feminella | website http://www.ericfeminella.com
Setting the tab key
onClipEvent (keyDown) {
        if (Selection.getFocus() == "_level0.movieClip.textboxVariable1"&&Key.isDown(Key.TAB)) {
                Selection.setFocus( "_level0.movieClip.textboxVariable2");
        } else if (Selection.getFocus() == "_level0.movieClip.textboxVariable2"&&Key.isDown(Key.TAB)) {
                Selection.setFocus( "_level0.movieClip.textboxVariable3");
        } else if (Selection.getFocus() == "_level0.movieClip.textboxVariable3"&&Key.isDown(Key.TAB)) {
                Selection.setFocus( "_level0.movieClip.textboxVariable1");
        }
}

//Or if you'd rather place the actions on a button, try this:


on (keyPress "") {
        if (Selection.getFocus() == "_level0.movieClip.textboxVariable1") {
                Selection.setFocus( "_level0.movieClip.textboxVariable2");
        } else if (Selection.getFocus() == "_level0.movieClip.textboxVariable2") {
                Selection.setFocus( "_level0.movieClip.textboxVariable3");
        } else if (Selection.getFocus() == "_level0.movieClip.textboxVariable3") {
                Selection.setFocus( "_level0.movieClip.textboxVariable1");
        }
}


Posted by: No name | website http://
Using getSelectedItem with ListBox Component
// Define following function in the same frame with the component
// Call it at the Property inspector as a Change Handler

function callURL() {
        getURL(listBox.getSelectedItem().data, "_blank");
}

// Instance name for the component is "listbox"
// Source file can be seen at "Scripting" category at "Movies" section.

Posted by: Mustafa Basgun | website http://www.basgun.com

<< Prev 5 |

Copyright 2000-2010 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.