2 Replies Latest reply on Aug 3, 2010 11:12 AM by nothing2k9

    Problem with input focus in combined flex and plain AS

    nothing2k9

      I'm writing game based on Flixel engine and Flex.

       

      Flex code here:

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application
           xmlns:mx="http://www.adobe.com/2006/mxml"
           layout = "absolute"
           width = "640"
           height = "480"
           applicationComplete = "appComplete()" xmlns:ns1="*">
           <mx:Style source="flex_game.css"/>

           <mx:Script>
                     <![CDATA[
                          import com.adamatomic.Mode.States.PlayState;
                          import flash.events.FocusEvent;

                          protected function appComplete():void
                          {                              
                               var game:Game2 = new Game2()
                               var display:display_ui_object = new display_ui_object(game);

                               this.addChild(display);
                               this.addChild(push);
                               this.addChild(console_out);
                               this.addChild(console_in);
                          }          

                     ]]>
           </mx:Script>

           <mx:TextArea
                id="console_in"
                x="5"
                width="630"
                height="98"
                editable="false"
                y="355"
                focusOut="PlayState.activate_player()" focusIn="PlayState.deactivate_player()"
                />
           <mx:TextInput
                id="console_out"
                x="5" y="454"
                width="552"
                color="#000000"
                focusOut="PlayState.activate_player()" focusIn="PlayState.deactivate_player()"
                />
           <mx:Button
                id="push"
                x="564"
                y="455"
                label="Жмак!"
                focusOut="PlayState.activate_player()" focusIn="PlayState.deactivate_player()"
                />
      </mx:Application>


      Part of AS code here:

       

      package
      {
           import flash.display.DisplayObject;
           import mx.core.UIComponent;

           public class display_ui_object extends UIComponent
           {
                public function display_ui_object (sprite: DisplayObject)
                {
                     super();

                     focusEnabled = true;
                              mouseFocusEnabled = true;

                     explicitHeight = sprite.height;
                     explicitWidth = sprite.width;               

                     addChild(sprite);
                }
           }
      }


      When I click on one of Flex widgets it gives focus, but when I click on game pane again (out of widgets) Flex widget doesn't lose a focus. How can I do it?