3 Replies Latest reply on Mar 1, 2010 11:41 AM by rgadiparthi

    Copying all the contents of a Vbox to a clipboard

    Prashant Waykar

      Hello sir,

       

      Can someone please help me out with copying the data inside a VBox to a clipboard.

       

       

      I have a Vbox and inside it there are 10 label objects along with a list component.

       

      Is there a way to copy all the data to the clipboard in one attempt.

      Thanks in advance.

        • 1. Re: Copying all the contents of a Vbox to a clipboard
          rgadiparthi Level 2

          here is the example

           

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
          <mx:VBox id="controls">
              <mx:Label id="o1" text="Test1"/>
              <mx:Label id="o2" text="Test1"/>
              <mx:Label id="o3" text="Test1"/>
              <mx:Label id="o4" text="Test1"/>
              <mx:Label id="o5" text="Test1"/>
              <mx:Label id="o6" text="Test1"/>
              <mx:Label id="o7" text="Test1"/>
              <mx:Label id="o8" text="Test1"/>
            <mx:List id="source" width="100%" color="blue"
                      dataProvider="{mystates.state}"/>       
          </mx:VBox>
              <mx:Model id="mystates">
                <states>
                  <state label="Alabama"/>
                  <state label="Alaska"/>
                  <state label="Arizona"/>
                  <state label="Arkansas"/>
                  <state label="California"/>
                  <state label="Colorado"/>
                  <state label="Connecticut"/>
                </states>
              </mx:Model>
              <mx:Script>
                  <![CDATA[
                      import mx.utils.ObjectProxy;
                      import mx.collections.ArrayCollection;
                     
                      private function copytoClickBoard():void
                      {
                          var arr:Array = [];
                          arr = controls.getChildren()
                          var copyData:String = "";
                          for each(var obj:Object in arr)
                          {
                              if(obj is Label)
                                  copyData +=obj.text + "\t\n";
                              if(obj is List)
                                  for each(var objx:ObjectProxy in obj.dataProvider)
                                  {
                                      copyData += objx.label+ "\t\n";
                                  }       
                          }
                      System.setClipboard(copyData);
                      }
                  ]]>
              </mx:Script>
              <mx:Button id="copy" label="Copy 2 CBoard" click="copytoClickBoard()"/>
          </mx:Application>

           

          Regards,

          1 person found this helpful
          • 2. Re: Copying all the contents of a Vbox to a clipboard
            Prashant Waykar Level 1

            Hello sir,

            Thanks for your help.

            I tried this demo but i have a repeater inside a vbox and i am not able to copy the contents to the clipboard can you please help me out.

             

            <VBox>

                 <Repeater count=10>

                      <Text/>

                 </Repeater>

            </VBox>

             

            Awaiting your reply.

            Thanks in advance.

            • 3. Re: Copying all the contents of a Vbox to a clipboard
              rgadiparthi Level 2

              here it is.

               

               

              <?xml version="1.0" encoding="utf-8"?>
              <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
              <mx:VBox id="controls">
              <!--     <mx:Label id="o1" text="Test1"/>
                  <mx:Label id="o2" text="Test1"/>
                  <mx:Label id="o3" text="Test1"/>
                  <mx:Label id="o4" text="Test1"/>
                  <mx:Label id="o5" text="Test1"/>
                  <mx:Label id="o6" text="Test1"/>
                  <mx:Label id="o7" text="Test1"/>
                  <mx:Label id="o8" text="Test1"/>
              -->        <mx:Repeater id="myRep" dataProvider="{myArray}">
                          <mx:Label
                              id="myLabel"
                              text="This is loop #{myRep.currentIndex}"  />
                      </mx:Repeater>       
                 
                <mx:List id="source" width="100%" color="blue"
                          dataProvider="{mystates.state}"/>      
              </mx:VBox>
                  <mx:Model id="mystates">
                    <states>
                      <state label="Alabama"/>
                      <state label="Alaska"/>
                      <state label="Arizona"/>
                      <state label="Arkansas"/>
                      <state label="California"/>
                      <state label="Colorado"/>
                      <state label="Connecticut"/>
                    </states>
                  </mx:Model>
                  <mx:Script>
                      <![CDATA[
                          import mx.utils.ObjectProxy;
                          import mx.collections.ArrayCollection;
                          import mx.controls.Label;
                          [Bindable]
                          public var myArray:Array=[1,2,3,4];

               

                        
                          private function copytoClickBoard():void
                          {
                              var arr:Array = [];
                              arr = controls.getChildren()
                              var copyData:String = "";
                              for each(var obj:Object in arr)
                              {
                                   if(obj is Label)
                                      copyData +=obj.text + "\t\n";
                                   if(obj is List)
                                      for each(var objx:ObjectProxy in obj.dataProvider)
                                      {
                                          copyData += objx.label+ "\t\n";
                                      }      
                              }
                          System.setClipboard(copyData);
                          }
                      ]]>
                  </mx:Script>
                  <mx:Button id="copy" label="Copy 2 CBoard" click="copytoClickBoard()"/>
              </mx:Application>