6 Replies Latest reply on Jun 11, 2012 3:02 PM by MatteoLegittimo

    Flex Mobile Error #2009: This method cannot be used on a text field with a style sheet.

    motionweb55 Level 1

      Hi i'm formatting some html in a mobile flex project with css.... I used some of the code supplied directly from adobe. As soon as a width is specifed for the text area as 100% it crashes...

       

      Error: Error #2009: This method cannot be used on a text field with a style sheet.

      at flash.text::TextField/replaceText()

       

      http://help.adobe.com/en_US/flex/mobileapps/WS19f279b149e7481c-3c2dbaa612bb06a5ea2-8000.ht ml

       

      <?xml version="1.0" encoding="utf-8"?>
      <!-- mobile_text/HTMLLinkView.mxml -->
      <s:View xmlns:fx="http://ns.adobe.com/mxml/2009" 
              xmlns:s="library://ns.adobe.com/flex/spark" title="HTMLText with Link"
              creationComplete="initView()">
          
          <fx:Declarations>
              <!-- Place non-visual elements (e.g., services, value objects) here -->
          </fx:Declarations>
          
          <fx:Script>
              <![CDATA[
                  import spark.components.supportClasses.StyleableTextField;
                  
                  private function initView():void {
                      var styles:String = "a { color: #33CCFF; } a:hover { color: #3366CC; text-decoration: underline; }";
                      var myStyleSheet:StyleSheet = new StyleSheet();
                      myStyleSheet.parseCSS(styles);
                      
                      StyleableTextField(ta1.textDisplay).styleSheet = myStyleSheet;
                      StyleableTextField(ta1.textDisplay).htmlText = "Click <a href='http://www.adobe.com'>here</a>.";
                  }
              ]]>
          </fx:Script>
          
          <s:TextArea id="ta1" width="100%"/>
          
      </s:View>

        • 1. Re: Flex Mobile Error #2009: This method cannot be used on a text field with a style sheet.
          Tyler Silcox

          *Bump*

           

          Any chance you've figured this out? To get even simple links to render with styles in a mobile app, I've only found one other option with StageWebView. Which I don't feel is an anywhere near an acceptable solution because of the different ways mobile browsers adjust the supplied text.

           

          Adobe, this is frustating, please help us out or at least let us know a fix is coming in 4.6. So far, all I've seen is:

           

          "Flex 4.6 solves the problem of cross device text input. Flex exposes the native text editing controls on every platform, enabling you to customize the keyboard and allow the user to experience the native UI for common operations such as selection, copy/paste, and spell checking."

           

          That doesn't mention anything about text display.

          • 2. Re: Flex Mobile Error #2009: This method cannot be used on a text field with a style sheet.
            Tyler Silcox Level 1

            After several days and several hundred google queries, I was able to create a workaround to this issue by simply using callLater():

             

            StyleableTextField(textArea.textDisplay).htmlText = htmlContent;
            
            callLater(function():void{
                 var styleSheet:StyleSheet = new StyleSheet();
                 styleSheet.parseCSS("a {color: #FFCC77; text-decoration: underline;}");
                 StyleableTextField(textArea.textDisplay).styleSheet = styleSheet;
            });
            

             

            I've tested on an iOS device and in the Android emulator. I don't have my Android testing device with me today, so I'm not sure if it fully works.

            • 3. Re: Flex Mobile Error #2009: This method cannot be used on a text field with a style sheet.
              matthew horn Level 3

              One other possibility, and this is a bit of a long shot, is that you need to load the style sheet on the main app, not in the view.

              • 4. Re: Flex Mobile Error #2009: This method cannot be used on a text field with a style sheet.
                Tyler Silcox Level 1

                matthew horn wrote:

                 

                One other possibility, and this is a bit of a long shot, is that you need to load the style sheet on the main app, not in the view.

                 

                Do you mean in the application stylesheet (for styling the flex application) or a StyleSheet object that can be applied to TextInputs and TextAreas? I'm very new to the world of Flex, but I have a default.css file with namespaces for use on my components, custom skins, ItemRenderers, etc. But that doesn't work for the limited styles available on StyleableTextField-ified text inputs within mobile apps...as far as I know.

                 

                And because I'm not sure if I'm missing something super simple, I also tried creating the StyleSheet variable in the main application and then applied it to the TextArea in my view:

                 

                // {main-app}.mxml
                public var defaultStyleSheet:StyleSheet;
                
                protected function init(event:FlexEvent):void {
                    defaultStyleSheet = new StyleSheet();
                    defaultStyleSheet.parseCSS("a { color: #33CCFF; } a:hover { color: #3366CC; text-decoration: underline; }");
                }
                

                 

                // ExampleView.mxml
                StyleableTextField(ta1.textDisplay).styleSheet = FlexGlobals.topLevelApplication.defaultStyleSheet;
                StyleableTextField(ta1.textDisplay).htmlText = "Click <a href='http://www.adobe.com'>here</a>.";
                

                 

                ...and I receive the same #2009 error which appears to be thrown when one of the base text objects calls defaultTextFormat(). So I figuring it's still an issue that the TextArea won't accept a stylesheet at this point in it's lifecycle...and why I think the callLater() method works. But I'd definitely like to know if this is a poor band-aid as well.

                • 5. Re: Flex Mobile Error #2009: This method cannot be used on a text field with a style sheet.
                  SpaceMarine

                  i got this error when i rotate the device with the calllater method.

                   

                  after hours of searching i had disable custon font for the field, and don´t get the error.

                  • 6. Re: Flex Mobile Error #2009: This method cannot be used on a text field with a style sheet.
                    MatteoLegittimo Level 1

                    I don't know if u  solved but try like this, should work:

                     

                     

                    <s:TextArea id="ta1" skinClass="spark.skins.mobile.TextAreaSkin" width="100%"/>