7 Replies Latest reply on Dec 15, 2009 5:23 PM by jdesko

    TextFlow with FXG

    jdesko Level 2

      I have a TextArea that I am trying to load an FXG image into.  If I create a TextArea with an inline image with the FXG component it works.  But, if I try to load an external xml with the same FXG component it will not work (text loads fine from the same ext. file).


      This is the minimized code:


      The ext. xml:


      <?xml version="1.0" encoding="UTF-8"?>

      <TextFlow xmlns="http://ns.adobe.com/textLayout/2008">

        <img source="{baby}"/>

        <p>this is a baby!</p>



      In the script I have:



      public var baby:Baby = new Baby;


      // using URLLoader to load in external textflow - this is the complete handler

      protected function helpLoader_completeHandler(event:Event):void


      helpContent.textFlow = TextConverter.importToFlow(helpLoader.data, TextConverter.TEXT_LAYOUT_FORMAT);




      In MXML


      // the ext. xml goes into below - this is where the image will not load


      <s:TextArea id="helpContent"


                width="100%" height="100%"



      // The below works





                     <s:img source="{baby}"/>




        • 1. Re: TextFlow with FXG
          Peter Farland Level 3

          The curly-brace {...} syntax for data binding is only supported at compile time and only when compiling MXML-G. The runtime components do not handle binding {...} syntax themselves and they would not understand the syntax when loading an XML document.



          • 2. Re: TextFlow with FXG
            jdesko Level 2

            Hello Peter;


            Thanks much for the reply.  The data binding was another effort to get the fxg to load (thanks for the info) ... I've tried in the ext. xml to no avail:


            <img source="baby"/> - I'm sure looking for a file named baby

            <img source="baby.fxg"/>

            <img source=baby/> - bad xml markup

            <img source = new Baby/> - bad xml



            but nothing that I'm doing is working, I'm sure user error.


            Any other suggestions would be greatly appreciated.




            • 3. Re: TextFlow with FXG
              jdesko Level 2

              In TextConverter.as it shows src and img and only lists loading JPEG, GIF, PNG,

              and SWF files. 


              So is there a way to load an fxg component in an external xml file (along with text) as your able to do with inline TextFlow in a TextArea?




              • 4. Re: TextFlow with FXG
                Peter Farland Level 3

                I don't know of a way to do that out of the box right now. Earlier in Gumbo we had a prototype parser that converted FXG XML into ActionScript objects at runtime but it has since been removed from the framework (and was removed before we introduced FXG 2.0). The team concentrated on getting compile time approaches working.


                There are two approaches to compiling FXG. One is to refer to an FXG document as a custom component: <local:MyFXG xmlns:local="*" />. The compiler converts most the FXG tags into primitive SWF instructions and links the root DefineSprite to a subclass of spark.core.SpriteVisualElement. This approach uses considerably much less memory and helps startup time but the graphic elements are not programmatically accessible and thus the asset is really a "static" vector graphic.


                The other option is to convert FXG to MXML-Graphics... i.e. change the <Library> tag, any <Definition> tags and any "place object" tag references to those definitions, and the <Private> tag into MXML 2009 language tags (e.g. <fx:Library>, <fx:Definition>, <fx:MySymbol>, <fx:Private>). The other graphics tags and their child property tags become Spark components, <s:Group>, <s:Ellipse>, <s:fill>, etc. A short cut for this second step is to map the default namespace to the Spark component library namespace and avoid having to add s: prefixes on all of the tags. e.g. xmlns="library://ns.adobe.com/flex/spark". The Spark components use the ActionScript drawing API to render themselves and the graphic elements can be manipulated at runtime. You can also take advantage of MXML-specific concepts such as data binding.


                To load a static FXG SWF asset or editable MXML-Graphics SWF at runtime you could try writing an FXG 2.0 Parser that would mimic what the compiler does and creates Spark ActionScript components on the fly. You'd have to make sure all of the graphics classes were linked into the SWF too. Alternatively you could try use the webtier compiler or write a simpler servlet that dynamically called the compiler to convert the FXG to a SWF as a pre-conversion step.

                1 person found this helpful
                • 5. Re: TextFlow with FXG
                  jdesko Level 2

                  Hello Peter;


                  public var thanks:String = "thanks for your time and insightful reply, very much appreciated,"


                  Many {thanks}


                  So, after what you had said, time being of the essence, for this part of the project I converted my FXG into gif's and use the gif's in the ext. xml.


                  I could replace each external xml with a custom component, so instead of loading xml into textFlow I could use a custom component based on say TextArea that would load into a container - but didn't want the overhead for this part of the project.


                  If Adobe wants to share the parser that you were working on it would be great to look at.


                  Again many {thanks},



                  • 6. Re: TextFlow with FXG
                    Peter Farland Level 3

                    Hey John,


                    I think it was removed in SVN revision 5545. An older version appears to still be tagged in an old milestone release but it should give you the general idea of what it did:

                    http://opensource.adobe.com/svn/opensource/flex/sdk/tags/ ex4/src/mx/graphics/Parser.as

                    • 7. Re: TextFlow with FXG
                      jdesko Level 2

                      Hello Peter;


                      Thanks much again,