3 Replies Latest reply on Sep 8, 2009 1:13 AM by chandly9

    Recover text to a TextArea

    chandly9 Level 1
      <?xml version="1.0" encoding="utf-8"?>
      <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" backgroundColor="white" 
      width="854" height="594" alpha="0.84">
          <mx:Script>
              <![CDATA[
              [Bindable]
              public var text:String;
      
              private function alimTexte():void{
                   var i:int;
                   
                   for (i=1;i<=10000;i++){
                        if ((i==1) || (i<=5000))
                        {
                        text="Hello you";
                        }
                        if ((i=5001) || (i<=10000))
                        {
                        text="Bonjour toi";
                        }
                   }
              }
              ]]>
          </mx:Script>
                <mx:TextArea text="{text}" x="347" y="165"/>
      
      </mx:Canvas>
      
      
      

      Hello,

       

      I would to recover a text from as3 and put it in a  textarea with a timer. The timer will be implemented later but for nom, I put another very bas solution so just have a look on the reception in the textarea which, actually, doesn't print :/ so i don't recover it and i don't know why ... Can you help me please ? Thx

       

       

       

      Can you rectify it and show me the right code because i spend a lot of hours on this problem and it makes me crazy :s ...

       

      Thank you very much

       

      Chandy9

        • 1. Re: Recover text to a TextArea
          TheFlexGuy Level 2

          I'm not sure I completely understand your goal, but I'll give you some help.

           

          I see you're using a for loop that counts to 10000, probably for your timer.  This will not work.  You need to make a Timer that will go off every 10 seconds like this:

          var timer:Timer = new Timer(5000);
          

          Then, you listen for the timer event, giving it a function

          timer.addEventListener(TimerEvent.TIMER, timerHandler);
          

          Create the timerHandler function that will be called every time the event happens (every 5 seconds in this case).  Note that I changed the variable you made from text to myText to make it less confusing.

          private function timerHandler(event:TimerEvent):void
          {
               if(myText == "Hello you")
               {
                 myText = "Bonjour toi";
               {
               else
               {
                 myText = "Hello you";
               }
          }
          

          Then, in the creationComplete handler or wherever you want to start the timer, you tell the timer to start counting.

          timer.start();
          

          As long as your TextArea is bound to myText, using text={myText} you should be fine.

           

          Does this all make sense?

           

          -Marty [ http://www.theflexguy.com ]

          Helpful/Answered? Please mark it as such.

          1 person found this helpful
          • 2. Re: Recover text to a TextArea
            chandly9 Level 1

            You understood what i want... but it doesn't work.

             

            Actually, as you have certainly remarked, i'm a flex newbie but here's my code :

             

             

             

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

            <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="1130" height="732">

            <mx:Script>

            <![CDATA[

            import flash.utils.Timer;

            public var timer:Timer= new Timer(5000);

            public var myText:String;

             

            private function Timer():void{

            timer.addEventListener(TimerEvent.TIMER, timerHandler);

             

            }

             

            private function timerHandler(event:TimerEvent):void

            {

                if(myText == "Hello you")

                {

                  myText = "Bonjour toi";

                }

                else

                {

                  myText = "Hello you";

                }

            }

             

            private function start():void{

            timer.start();

             

            }

             

            ]]>

            </mx:Script>

             

            <mx:TextInput text="{myText}"/>

             

            </mx:Canvas>

             

             

             

            I have 2 errors :

             

            the first : The type "Timer" is not found -> I don't understand because i put the library

            the second : impossible to build a method in a builder

             

            Can you explain please Thank you

            • 3. Re: Recover text to a TextArea
              chandly9 Level 1

              Someone please ?