3 Replies Latest reply on Feb 9, 2010 10:21 AM by cyber0897

    this.textDisplay does not seem to work...  is there a work around for this??

    cyber0897 Level 1

      hey guys... so im trying to create a text box which would have a prompt, and on focus of that textbox it would clear out that prompt from in the text box...

      the problem is i have no idea why its not working... it seems to be displaying the prompt... but my onfocus event is never called...

       

      it seems as if i never get into the if statement that says

      if(instance == this.textDisplay)

       

      the textDisplay used to be textView... but after tons of research i found out that textView has been changed to textDisplay...

       

      any help why i cant getinto that if statement would be GREATLY appretiated!!! ive spent over a day on this stupid issue... lol

       

       

      thanks a ton for all you help

       

       

      the code i have is...

       

       

      main app:

      <textbox:advancedTextInput id="fileName" prompt="File Name"
           skinClass="components.textbox.advancedTextInputSkin" />
      

       

       

      in the advancedTextInput.as file...

      package components.textbox
      {
           import flash.events.FocusEvent;
           
           import spark.components.TextInput;
           
           public class advancedTextInput extends TextInput
           {
      
                public function advancedTextInput()
                {
                     super();
                }
                
                [SkinPart(required="true")]
                
                public var promptView:TextInput;
      
                [SkinState("focused")];
      
                private var _prompt:String
                
                private var promptChanged:Boolean;
                
                [Bindable]
                
                public function get prompt():String
                {
                     return _prompt;
                }
                
                public function set prompt(v:String):void
                {
                     _prompt = v;
                     promptChanged = true;
                     invalidateProperties();
                }
                
                override public function set text(val:String):void
                {
                     super.text = val;
                     
                     if (promptView && text == "")
                     {
                          promptView.visible = true;     
                     }
                }
                
                override protected function commitProperties():void
                {
                     super.commitProperties();
                     
                     if (promptChanged)
                     {
                          if (promptView)
                          {
                               promptView.text = prompt;     
                          }
                          
                          promptChanged = false;
                     }
                }
                
                override protected function partAdded(partName:String, instance:Object):void
                {
                     super.partAdded(partName, instance);
                     
        ------------------>     if (instance == this.textDisplay)
                     {
                          this.textDisplay.addEventListener(FocusEvent.FOCUS_IN, onFocusInHandler);
                          this.textDisplay.addEventListener(FocusEvent.FOCUS_OUT, onFocusOutHandler);
                     }
                     
                     if (instance == promptView)
                     {     
                          promptView.text = prompt;
                     }
                }
                
                override protected function partRemoved(partName:String, instance:Object):void
                {
                     super.partRemoved(partName, instance);
                     
        ------------------>     if (instance == this.textDisplay)
                     {
                          this.textDisplay.removeEventListener(FocusEvent.FOCUS_IN, onFocusInHandler);
                          this.textDisplay.removeEventListener(FocusEvent.FOCUS_OUT, onFocusOutHandler);
                     }
                }
      
                private function onFocusInHandler(event:FocusEvent):void
                {
                     if (promptView)
                     {
                          promptView.visible = false;
                     }
                }
                
                private function onFocusOutHandler(event:FocusEvent):void
                {
                     if (promptView)
                     {
                          if (text == "")
                          {
                               promptView.visible = true;     
                          }
                          else
                          {
                               promptView.visible = false;
                          }
                     }
                }
                
           }
      }
      

       

       

       

      and the skin contains....

      <s:sparkSkin>
      ...
      ...
      ...
           <s:RichEditableText 
                id="viewText"
                bottom="1"
                left="1"
                paddingBottom="3"
                paddingLeft="3"
                paddingRight="3"
                paddingTop="5"
                right="1"
                top="1"
                lineBreak="explicit"
                />
           
           <!-- prompt -->
           <s:TextInput 
                id="promptView"
                bottom="1"
                color="#999999"
                fontStyle="italic"
                left="1"
                paddingBottom="3"
                paddingLeft="3"
                paddingRight="3"
                paddingTop="5"
                right="1"
                top="1"
                />
           
      </s:SparkSkin>
      
        • 1. Re: this.textDisplay does not seem to work...  is there a work around for this??
          Flex harUI Adobe Employee

          There is no component with id="textDisplay" in your skin

          1 person found this helpful
          • 2. Re: this.textDisplay does not seem to work...  is there a work around for this??
            cyber0897 Level 1

            oh oops.. i actually changed that... my skin ended up being

             

                <s:RichEditableText
                    id="textDisplay"
                    bottom="1"
                    left="1"
                    paddingBottom="3"
                    paddingLeft="3"
                    paddingRight="3"
                    paddingTop="5"
                    right="1"
                    top="1"
                    lineBreak="explicit"
                    />

             

             

            but it still does not work...

            • 3. Re: this.textDisplay does not seem to work...  is there a work around for this??
              cyber0897 Level 1

              actually... since my code was not working at all.. i just decided to changed the entire thing... and i ended up with

               

              package components.textbox
              {
                   import flash.events.FocusEvent;
                   
                   import mx.controls.TextInput;
                   
                   public class advancedTextInput extends TextInput
                   {
                        private var _defaultText:String;
                        
                        public function advancedTextInput()
                        {
                             super();
                             if( text == ""){
                                  text = defaultText;
                                  setStyle("color", "0x808080")
                                  setStyle("fontStyle","italic");
                             }
                             addEventListener(FocusEvent.FOCUS_IN, FocusIn);
                             addEventListener(FocusEvent.FOCUS_OUT, focusOut);
                        }
                        
                        public function set defaultText(value:String):void{
                             _defaultText = value;
                             if( text == ""){
                                  text = defaultText;
                                  setStyle("color", "0x808080")
                                  setStyle("fontStyle","italic");
                             }else{
                                  setStyle("color", "0x0B333C")
                                  setStyle("fontStyle","none");
                             }
                        }
                        
                        public function get defaultText():String{
                             return _defaultText;
                        }
                        
                        private function FocusIn(event:FocusEvent):void{
                             if( text == defaultText ){
                                  text = "";
                             }
                             setStyle("color", "0x0B333C")
                             setStyle("fontStyle","none");
                        }
                        private function focusOut(event:FocusEvent):void{
                             if( text == "" ){
                                  text = defaultText;
                                  setStyle("color", "0x808080")
                                  setStyle("fontStyle","italic");
                             }else{
                                  setStyle("color", "0x0B333C")
                                  setStyle("fontStyle","none");
                             }
                             
                        }
                        
                   }
              }
              

               

               

               

              this code works like a camp... thanks a ton for you help tho...!