What class should I extend for this custom control?

The code below is my attempt at a mxml control to replace a custom context-menu  that my app needs on certain textInput controls.  Characters not on the keyboard are inserted into the text, replacing any selection, if applicable.  Flex AIR apps (which I need for local access to SQLite) don't let me do custom contextmenus when the control is not top-level.
The custom component is encapsulated now in a Panel but I would like to have the composite control be nothing more than a textInput and a PopUpMenuButton right next to it.  Is that possible—not to have a container?  If so,  what class should I extend, if creating this as an ActionScript component?
Thanks for the advice.
<?xml version="1.0" encoding="utf-8"?>
<mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="228" height="64"  creationComplete="onInit();" >
    <mx:TextInput id="mytextinput"   height="20"></mx:TextInput>   
    <mx:PopUpMenuButton id="mybutton" itemClick="onCharSelected(event);" x="159" y="-2" label="æ" width="41"  />
    <mx:Script>
     <![CDATA[
         import mx.utils.StringUtil;
         import mx.events.MenuEvent;
         import mx.events.ItemClickEvent;
         import mx.controls.TextArea;
        import mx.controls.Alert;
        import flash.events.*;
        import flash.display.Sprite;    
        import mx.collections.ArrayCollection;
            // use a point to track the selection-start and selection-end position for the text field
            private var pt:Point=new Point;
            private var chars:ArrayCollection = new ArrayCollection(
                [ {label:"ð", data : "ð"},
                  {label:"æ", data:"æ"},
                  {label:"þ", data:"þ"} ]);
                // track the selection positions as the mouse is moved or text is entered
              private function onMouseEvent(e:MouseEvent): void{
                  pt.x=this.mytextinput.selectionBeginIndex;
                  pt.y=this.mytextinput.selectionEndIndex;
              private function trackSelectionIndices(e: Event):void {
                 pt.x=this.mytextinput.selectionBeginIndex;
                  pt.y=this.mytextinput.selectionEndIndex;  
            private function onInit():void {
                this.mytextinput.addEventListener(Event.CHANGE, trackSelectionIndices);
                this.mytextinput.addEventListener(MouseEvent.MOUSE_DOWN, onMouseEvent);
                this.mytextinput.addEventListener(MouseEvent.MOUSE_UP, onMouseEvent);
                this.mybutton.dataProvider = chars;                     
            private function onCharSelected(e:MenuEvent):void {               
                doInsert( e.item.data.toString(), this.mytextinput);
        // insert the character chosen from the popup into the text field, replacing any selection, and then reset the insertion point
         private function doInsert(s:String, trgt:Object):void {
            var v:String = TextInput(trgt).text;
            var pre:String =v.substr(0,TextInput(trgt).selectionBeginIndex);
            var post:String=v.substr(TextInput(trgt).selectionEndIndex, v.length-TextInput(trgt).selectionEndIndex);
            var result:String = pre + s + post;
            TextInput(trgt).text=result;
            TextInput(trgt).setSelection(TextInput(trgt).selectionBeginIndex+s.length,TextInput(trgt) .selectionBeginIndex+s.length);
          ]]> 
    </mx:Script>        
</mx:Panel>

Wiping perspiration from my brow as I abandon the difficult approach.
Here is the simpler approach where HBox encapsulates the TextInput and PopUpMenuButton. I am trying to figure out how to let the TextInput keep its selection highlight when it loses focus to the PopupMenuButton: setSelection does not cause the repaint.
package Search
    import flash.events.*;
    import flash.geom.Point;
    import mx.collections.ArrayCollection;
    import mx.containers.HBox;
    import mx.controls.PopUpMenuButton;
    import mx.controls.TextInput;
    import mx.events.MenuEvent;
    public class UnicodeCharPopupMenu extends HBox
        public function UnicodeCharPopupMenu()        {   
                    super();   
                    Init();
        private var mytextinput:TextInput = new TextInput;
        private var mybutton:PopUpMenuButton = new PopUpMenuButton;
        private function Init():void {
            mytextinput.width=100;
            mytextinput.height=22;
            mybutton.width=44;           
            this.width=200;
            this.height=20;
            visible=true;
           mybutton.addEventListener(FocusEvent.FOCUS_IN, onMenuGotFocus;
            mytextinput.addEventListener(Event.CHANGE, trackSelectionIndices);
            mytextinput.addEventListener(MouseEvent.MOUSE_DOWN, onMouseEvent);
            mytextinput.addEventListener(MouseEvent.MOUSE_UP, onMouseEvent);
            mybutton.addEventListener( MenuEvent.ITEM_CLICK, onCharSelected);
            //mybutton.addEventListener(MenuEvent.MENU_HIDE, onMenuHide);
            //mybutton.addEventListener(MenuEvent.MENU_SHOW, onMenuShow);
            mybutton.dataProvider = chars;  
            addChild(mytextinput);
            addChild(mybutton);           
        // use a point to track the selection-start and selection-end position for the text field
        private var pt:Point=new Point;
          private var chars:ArrayCollection = new ArrayCollection(
                [ {label:"ð", data : "ð"},
                  {label:"æ", data:"æ"},
                  {label:"þ", data:"þ"} ]);
      //button got focus, repaint selection highlight
        private function onMenuGotFocus(e:FocusEvent): void {           
             mytextinput.setSelection(pt.x, pt.y);
        // nothing selected, menu closed
        private function onMenuHide(e:MenuEvent): void {
            if (e.item.data==null) {
                mytextinput.setFocus();
        private function onCharSelected(e:MenuEvent):void {             
                doInsert( e.item.data.toString(), mytextinput);
       public function getText():String {
                return mytextinput.text;
            // track the selection positions as the mouse is moved or text is entered
             private function onMouseEvent(e:MouseEvent): void{
                 pt.x=mytextinput.selectionBeginIndex;
                 pt.y=mytextinput.selectionEndIndex;
             private function trackSelectionIndices(e: Event):void {
                pt.x=mytextinput.selectionBeginIndex;
                 pt.y=mytextinput.selectionEndIndex;  
             private function doInsert(s:String, trgt:Object):void {
             var v:String = TextInput(trgt).text;
             var pre:String =v.substr(0,pt.x);
              var post:String=v.substr(pt.y, v.length-pt.y);
            var result:String = pre + s + post;
            TextInput(trgt).text=result;
            TextInput(trgt).setFocus();
            TextInput(trgt).setSelection(pt.x+s.length,pt.x+s.length);
            pt.x = pt.x + s.length;
            pt.y = pt.x;          

Similar Messages

  • What query should be created for this case

    Here are those classes:
    Folder{
        String name;
        @ManyToOne
        Subject owner;
    Subject {
        String name;
    }What query should I create in order to: find out if there is an actual Folder for a Subject with the name X in the database ?
    Actually, the question is kinda stupid, but im not experienced with queries....

    javaUserMuser wrote:
    Here are those classes:
    Folder{
    String name;
    @ManyToOne
    Subject owner;
    Subject {
    String name;
    }What query should I create in order to: find out if there is an actual Folder for a Subject with the name X in the database ?Can't tell based on the info you posted. These are Java objects, and queries deal with relational tables.
    Your naming is confusing. Subject and owner are two very different things.
    If I had two tables like this:
    CREATE TABLE IF NOT EXISTS owners
        owner_id bigint not null auto_increment,
        name varchar(80),
        primary key(owner_id)
    CREATE TABLE IF NOT EXISTS folders
        folder_id bigint not null auto_increment,
        name varchar(80),
        owner_id bigint   
        primary key(folder_id),
        foreign key(owner_id) references(owners)
    );I'd write the JOIN query this way:
    SELECT f.name, o.name
    FROM folders as f, owners as o
    WHERE o.owner_id = ?
    AND o.owner_id = f.owner_idYou realize, of course, that if you're using EJB3 as the annotations suggest, that you don't write any SQL. EJB3 generates it dynamically for you.
    %

  • What classes should i use for graphics?

    I was wondering, what is the most effecient way of going about drawing 2d graphics for a game...
    use Java2D, swing, GBFrame, whatever else is out there, ect. ect.
    Your suggestions will be very much appreciated, thanks!

    Hi!
    Thank you very much for your help, I appreciate it a lot.
    While I test my server, I execute ping www.myclienthost.com -t (my client games are in other office, in the same building, but different ISP) and I don't see anything strange, so I guess network is working perfectly. However, if I use wireshark (sniffer) and I see that my system fails (server does not send acks so client disconnects) is because my acks messages are not sended for 6 o 7 seconds (it should send them every 2 or 3). It seems thread is blocked. and after 6 or 7 seconds one message with 2 or 3 acks together is sent. So, I see that the thread handler blocked for a few seconds and this is doing my server is failing. Why client handler thread on my server is blocked? One question: every 2 or 3 seconds I have a thread that uses sleep that iterates thru client handlers and takes OutputStream and send one ack message for every client handler. My question is, in client handler class I have a method called SendInfo(String whatever) which encrypts and sends through OutputStream, should I protectd this method from accesing from two threads??? as acks thread and client thread can access at the same time. Could this be the problem??
    EDIT: In my previous post I forgot to say what I found out with wireshark. Here I explain it. Sorry.
    By the way, how can I debug threads?? I would like to know if my client thread is blocked in that critical moment.
    Thanks a lot for your ideas and sorry for my English.
    Edited by: Ricardo_Ruiz_Lopez on Jan 22, 2009 7:38 AM

  • What loop should I use for this?

    for (int j=0; j<8; j++) {
                                source.setBackground(EXIT_COLORS[j]);
                                if (j==7)
                                     break;
                                }[/code
    okay, what i'm trying to do here, is display a color object from an array EXIT_COLORS[], which has 8 colors in it. Now I only want to display all of these colors 8 times. right now I can only diplay the last color or the first...I tried double for loops, and it didn't seem to work either...if you have an idea please help                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    sorry about that...I dont' need a break...I'm just trying different things to see if it'll work...
    see, the problem is, that every time my method runs i want one specific color to be displayed on a button, the next time it is ran, i want the next color in the array to be displayed...until the end of the array is reached, then I don't want any more to be displayed...But I can't figure out how to do this...
    here is my method:
         private void updateTiles() {     
                 // Now draw the tiles accordingly
            for (int r=0; r<size; r++) {
                 for (int c=0; c<size; c++) {
                      JButton aButton = view.getFloorTileButton(r*size + c);
                          if ((aButton.isSelected()) && (mode == EDIT_WALL_MODE)){
                               aButton.setBackground(Color.gray);
                      else if((aButton.isSelected()) && (mode == SELECT_EXITS_MODE)){
                          for (int j=0; j<8; j++){
                                aButton.setBackground(EXIT_COLORS[j]);
                       else if(mode == WAIT_MODE)
                           aButton.setBackground(Color.white);
                 // Set the text for the floor tile if it needs to be set
                     // Set the background color for the floor tile
            // Display the path if necessary (in Part C)
         }

  • Is Flash what I should be using for this simple animation?

    Hi I have a fairly simple question...
    Im working on a project which started with simple drawings of
    a particular animal. One of the drawings ive done involves the
    motion of part of this animal. The next portion of this assignment
    requires me to begin working digitally, and recreating these
    drawings precisely in Autocad.
    The problem is that I need essentially create a storyboard of
    images showing the motion of this animal in detail. So essentially
    im going to need 40+ frames showing this motion. It would be the
    equivalent of creating a flip book animation, but im going to be
    tiling all these frames next to eachother.
    Now as opposed to drawing 40+ separate images I had the idea
    to use Flash to produce these images for me.
    Heres essentially what I want to do:
    - Scan the drawings ive done
    - Reproduce them digitally through Autocad
    - Import these drawings into Flash (either as Autocad files
    or I can convert them to Illustrator files)
    - Basically have two images... 1 at the start of the motion
    and 1 at the end of the motion, and use flash tween's to
    extrapolate the motion in between.
    So ideally I could create 40 frames, with the 1st keyframe
    showing the beginning of the motion, the 40th showing the final
    stage of motion, and each frame in between providing me with the
    separate drawing that I need.
    Any thoughts or advice on how I can go about doing this? I
    havent used Flash in years so im still relatively unskilled with
    it...
    Thanks so much for your help!!

    I agree with Gibbah. Flash doesn't do magic with tweens. Of
    course, you can try. But if you're looking for NATURAL motion, then
    it needs to be drawn naturally-by hand.
    Sure, you can try it in Flash, but at best it will help you
    to tween every 4th drawing or so (so you'll still need 10 key
    drawings), and you'll spend ages tweaking the tweens, since (I
    repeat) Flash doesn't do magic with tweens, nor does any other
    software. You're talking of 4-legged animal movement, which I
    assume includes walking, which is a pretty complicated thing: 4
    legs, each double-jointed, plus the feet, then a body which bends,
    and the head and neck which move up and down. You'll have to
    separate each leg, the body and the head, at the very least, tween
    each of these, then go back and fix where the tweens come out all
    screwy.
    As for scanning, you can scan line artwork (preferably very
    clean lines done with pen or dark pencil) and then vectorize them
    directly in Flash. No need for the Autocad stage.
    To be honest, I think you'll find it faster to do the 40
    drawings individually. Check a good reference book such as the
    famous Eadweard Muybridge (yes, I spelled it correctly) photos of
    animal movements, and then you can rotoscope these (that is, trace
    them). You'll end up with less frustration and a gorgeous animation
    which looks natural, not machine-made. You could do the tracing
    directly in Flash as well, using the onion skin mode to help
    you.

  • What t_code should be used for migration?

    Hello there,
    our user wants to  migrate  "output vat" account after being audited.
    actually , they start using SAP from 1st. January.2009 but now needs to migrate for reconciliation purpose.
    Journal should be 40) output VAT   /      50) Beginning Balance-BS.
    Since this output VAT does not need any tax code and base amount, i think normal FI transaction like F-02 is not an answer.
    Furthermore, LSMW is not strongly recommended at this time, considering line item to be created.
    Could you let me know what t_code should be used for this case?
    BR.
    J.
    Edited by: Jimmy Choi on Jun 30, 2009 5:41 PM

    Hi
    Note down the G/L accounts you are posting.
    Option 1 :In OBD4 see the account group. change the tax category mandatory to optional field for running the lsmw. afte completion, set the status as earlier.
    Option 2: goto fs00-> see the field status group.-> double click on the FSG-> see the taxes -> make the fields optional.
    with regards
    siva
    Edited by: Siva Rama Krishna Yanamandra on Jul 2, 2009 1:12 AM

  • Need Help..what should i use for this

    hello friends, i have to write a program which will load an xml file reader class at run time and depending on the content of xml file i'm going to generate mapping.. e.g xml file- <MyMapping> <ATO> <security type=int> </ATO> <FIX> <symbol type=String> </FIX> </MyMapping> Now i want to change the content of xml file without restarting my running application..changes should be reflected at runtime... also my xml file will contain nearly 1000 lines..so in this case which technique should i use whether i use JAXB which will give the classes of my xml file or any other ?? Also if i use JAXB whether JAXB gives classes corrsponding to my xml nodes (e.g ATO.java as per above example).

    daitkarsachin wrote:
    hi ,
    here is my question again..my xml will have
    <Message>
    <ATO>
    <somefiled="X" type=int value=35 />
    </ATO>
    <FIX>
    <somefiled="Y" type=String value=50 />
    <FIX>
    </Message>
    Now first i have to parse this xml ..then my java program is going to accept value from user ..and depending on user specified value i've to use either ATO or FIX fields...e.g if user value is 35 then my program should use fields within ATO node.
    You will read the XML structure into some kind of memory model. When the user supplies a value you will search for a matching value (likely from a collection such as a map or list) and return the value in that object that you locate.
    what should be done for this ..
    See above.
    and what if i change values in my xml file..will i have to restart my application to load xml again ?
    If you change the file on the filesystem, you should simply be able to re-parse the XML file and update your in-memory model. If you instead update your in memory-model, you can serialize the model back to XML on the filesystem. Neither needs to necessarily have anything to do with application start-up (other than the fact that you would normally read in the XML model then, but updating is a separate concern, as would re-reading it).
    - Saish

  • I am trying to understand the licensing procedures for using tabKiller for 3.5.7 firefox. Who should I contact for this? I do not see any customer service phone number for Firefox

    I am trying to understand the licensing procedures for using tabKiller for 3.5.7 firefox. Who should I contact for this? I do not have the customer service phone number for Firefox

    Tab Killer is not created by Mozilla, it is created by a private individual who has made it available at no cost for other people to use.

  • I can't install any software,it said iOS 4.3,iOS 5, etc required.what should I do for this iOS....????

    I can't install any software,it said iOS 4.3,iOS 5, etc required.what should I do for this iOS....????

    Connect it to iTunes on a computer and check for updates.
    (74556)

  • What should be done for this ?

    hi ,
    here is my question ..my xml will have
    <Message>
    <ATO>
    <somefiled="X" type=int value=35 />
    </ATO>
    <FIX>
    <somefiled="Y" type=String value=50 />
    <FIX>
    </Message>
    Now first i have to parse this xml ..then my java program is going to accept value from user ..and depending on user specified value i've to use either ATO or FIX fields...e.g if user value is 35 then my program should use fields within ATO node.
    what should be done for this ..
    and what if i change values in my xml file..will i have to restart my application to load xml again ?

    I have changed your XML to make it well formed. Please refer this further in this reply.
    Well Formed XML:
    <Message>
         <ATO somefiled="X" type="int" value="35"/>
         <FIX somefiled="Y" type="String" value="50"/>
    </Message>
    daitkarsachin wrote:Now first i have to parse this xml ..then my java program is going to accept value from user ..and depending on user specified value i've to use either ATO or FIX fields...e.g if user value is 35 then my program should use fields within ATO node.
    what should be done for this ..A simple XPath Query can do trick for you, it can give you ATO or FIX element according to user specified value. XPath query can be:
    // replace ##user_specified_value## with value user enters.
    String xPathquery= "/Message/child::*[@value='##user_specified_value##']";
    daitkarsachin wrote:and what if i change values in my xml file..will i have to restart my application to load xml again ?Not necessary to restart application but you need to parse or reload updated XML file again.

  • What classes should I use to send/receive bytes inmediately?

    What classes should I use to send/receive bytes inmediately? I mean, without using any buffers or whatever (I will implement this on my app), just the faster method.
    Is InputStream/OutputStream the lowest level choice?
    Thanks!

    Hi!
    Thank you very much for your help, I appreciate it a lot.
    While I test my server, I execute ping www.myclienthost.com -t (my client games are in other office, in the same building, but different ISP) and I don't see anything strange, so I guess network is working perfectly. However, if I use wireshark (sniffer) and I see that my system fails (server does not send acks so client disconnects) is because my acks messages are not sended for 6 o 7 seconds (it should send them every 2 or 3). It seems thread is blocked. and after 6 or 7 seconds one message with 2 or 3 acks together is sent. So, I see that the thread handler blocked for a few seconds and this is doing my server is failing. Why client handler thread on my server is blocked? One question: every 2 or 3 seconds I have a thread that uses sleep that iterates thru client handlers and takes OutputStream and send one ack message for every client handler. My question is, in client handler class I have a method called SendInfo(String whatever) which encrypts and sends through OutputStream, should I protectd this method from accesing from two threads??? as acks thread and client thread can access at the same time. Could this be the problem??
    EDIT: In my previous post I forgot to say what I found out with wireshark. Here I explain it. Sorry.
    By the way, how can I debug threads?? I would like to know if my client thread is blocked in that critical moment.
    Thanks a lot for your ideas and sorry for my English.
    Edited by: Ricardo_Ruiz_Lopez on Jan 22, 2009 7:38 AM

  • Class type not defined for this object type

    Hi Friends,
    Could u please guide me ?..We have a requirement to extract some data from classification system.
    This is related with class type 023 - Batch
    I want to use the following parameters in CTBW.
    basis datasource :Z_BATCH_ATTR
    class type : 023
    object table :MCHA
    Datasource type : ATTR
    I am getting an error "Class type not defined for this object type" when i enter the above entries in CTBW.
    The only way I'm being able to make this work is changing object table from MCHA to MCH1.
    This solution does not fit me bacause MCH1 table dont have Plant as Key, and I need it.
    Do you know what should I do to solve this?
    Thanks in advance

    Hi,
    I believe we have to use the list of standard "Basis DataSource", as I'm also stuck with the same issue. Let me know what Basis Data source you selected in this case.
    As I'm trying to extract Batch attributes from "AUSP" Table.
    I have given class type= 023
    Obj Table= AUSP
    But not sure which "basis datasource" I need to select.
    Thanks,
    Satish

  • What are the license conditions for the customer ?

    What is the license agreement for the customer to use Beehiveonline ? Is it similar as the OUM Customer model copied below? thanks Francis
    OUM Customer Program: The OUM Customer Program allows customers to obtain copies of the method for their internal use by contracting with Oracle for a services engagement of two weeks or longer. Customers who have a signed contract with Oracle and meet the engagement qualification criteria as published on Customer tab of the OUM Website, are permitted to download the current release of OUM for their perpetual use. They may obtain subsequent releases published during a renewable, three-year access period.

    Hi,
    We do not have a license requirement for BeehiveOnline as this is a service provided by oracle for Oracle customers, partners etc. to allow them to work more efficiently with Oracle. It is not a system that the customer can control as the groups are maintained by the Oracle,contact.
    We rely on the normal terms and conditions that all users sign up to when they create an oracle.com website account.
    So in short - it is a free-to-use service licensed under the same agreement as the normal oracle.com websites acount.
    Phil

  • My MacBook Pro doesn't start; in safe mode shift CMD V the message "disk0s2: media is not present" is written on the screen repeatedly but the MacBook doesn't start.  Do you have any ideas of why this should be or what I should do to resolve this?

    My MacBook Pro doesn't start; in safe mode <shift CMD V> the message "disk0s2: media is not present" is written on the screen repeatedly but the MacBook doesn't start.  Do you have any ideas of why this should be or what I should do to resolve this?  Thanks  Eamonn

    Thanks for these suggestions: I have tried safe mode re-starts (both "verbose" and simple "shift" + power) to no avail.  I get the error message "disk0s2: media is not present".  Following this I inserted the installation disc and from there ran disc utility.  The "Verify Disk" indicated an error " invalid sibling link" which it could not repair.
    I also tried to completely re-format/erase the disk, but again got an error message "disk object invalid or unable to serialize".
    Any ideas of what could be causing this or the best solution?  I fear I am fast running out of options.

  • What class should be imported to resolve the error

    Dear all,
    would you please tell me that what class should i import to resolve the error for PreparedStatement.
    plz mention the import statement
    Error(437,13): class PreparedStatement not found in class oracle.apps.ak.cacheoffice.server.CacheOfficeAMImpl

    import java.sql.PreparedStatement;

Maybe you are looking for