2 Replies Latest reply on Oct 26, 2011 12:47 AM by donderse

    Add textareas with xml

    donderse

      Hello everyone,

       

      I want to add some textareas with values from an xml file:

       

       

      <?xml version="1.0" encoding="utf-8"?>
      <text>
                <item x="10" y="100" width="100" height="20">Hallo wereld</item>
                <item x="10" y="140" width="100" height="20">Hallo wereld</item>
                <item x="10" y="160" width="100" height="20">Hallo wereld</item>
                <item x="10" y="180" width="100" height="20">Hallo wereld</item>
      </text>
      
      

       

      I need the textareas to be added to an group.

      is there an easy way to do this in flex?

      This is what i have so far:

       

      <?xml version="1.0" encoding="utf-8"?>
      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
                                       xmlns:s="library://ns.adobe.com/flex/spark" 
                                       xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
                                       creationComplete="hello.send()">
                <s:layout>
                          <s:BasicLayout/>
                </s:layout>
        
                <fx:Script>
                          <![CDATA[
                                    import mx.collections.ArrayCollection;
                                    import spark.components.TextArea;
        
                                    private function addText():void{
                                              var text:TextArea = new TextArea();
                                              text.width = 300;
                                              text.height = 200;
                                              text.text = "Hallo wereld";
                                              text.x = 20;
                                              text.y = 20;
                                              pnl1.addElement(text);
                                    }
                          ]]>
                </fx:Script>
        
        
                <fx:Declarations>
                          <s:Scale id="scaler" autoCenterTransform="true" target="{pnl1}" duration="10" scaleYTo="{vs.value*0.10}" scaleXTo="{vs.value*0.10}"/>
                          <s:HTTPService 
                                    id="hello" 
                                    url="xml/hello.xml"
                                    result="addText()"/>
                </fx:Declarations>
        
                <s:Group id="pnl" width="600" height="400" verticalCenter="0" horizontalCenter="0" clipAndEnableScrolling="true">
                          <s:Rect top="0" left="0" bottom="0" right="0">
                                    <s:stroke>
                                              <s:SolidColorStroke id="borderStroke" weight="1"/>
                                    </s:stroke>
                          </s:Rect>
                </s:Group>
      </s:Application>
      
      

       

      Thanks!

       

      Sander Groen.

        • 1. Re: Add textareas with xml
          Jason Szeto Level 3

          Check out the XML class to see how you can navigate your XML.

          • 2. Re: Add textareas with xml
            donderse Level 1
            Ok this is what i have so far:

            <?xml version="1.0" encoding="utf-8"?>
            <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
                                             xmlns:s="library://ns.adobe.com/flex/spark" 
                                             xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
                                             creationComplete="hello.send()">
                      <s:layout>
                                <s:BasicLayout/>
                      </s:layout>
              
                      <fx:Script>
                                <![CDATA[
                                import spark.components.TextArea;
                                import mx.rpc.events.ResultEvent;
                                
                                private function addText(event:ResultEvent):void {
                                    for(var i:Number=0;i<event.result.text.item.length;i++){
                                        var text:TextArea = new TextArea();
                                        text.width = event.result.text.item[i].@[width];
                                        text.height = event.result.text.item.@height;
                                        text.text = event.result.text.item[i];
                                        text.x = event.result.text.item[i].@x;
                                        text.y = event.result.text.item[i].@y;
                                        pnl.addElement(text);
                                    }
                                }
                                ]]>
                      </fx:Script>
              
              
                      <fx:Declarations>
                                <s:HTTPService 
                                          id="hello" 
                                          url="xml/hello.xml"
                                          result="addText(event)"/>
                      </fx:Declarations>
              
                      <s:Group id="pnl" width="600" height="400" verticalCenter="0" horizontalCenter="0" clipAndEnableScrolling="true">
                                <s:Rect top="0" left="0" bottom="0" right="0">
                                          <s:stroke>
                                                    <s:SolidColorStroke id="borderStroke" weight="1"/>
                                          </s:stroke>
                                </s:Rect>
                      </s:Group>
            </s:Application>
            

             

            I succesfully loaded the text in the TextArea's.

            But I can't access the attributes for the width, height x and y values the way I did.

             

            Any ideas why this happens?