3 Replies Latest reply on Jun 7, 2009 10:12 PM by Flex harUI

    Autoscroll

    webguy5612

      Hello, I'm trying to autoscroll some text but its not working. Can someone help me? Here is my code:

       

      <mx:Script>
           <![CDATA[
               import flash.display.MovieClip;
              import flash.media.Sound;
              import flash.events.Event;
              import flash.net.URLRequest;
              import flash.media.SoundChannel;
              import flash.events.TextEvent; 
                
                public var _sound:Sound = new Sound();
                public var _soundChannel:SoundChannel;
                public var _resumeTime:Number;
                public var _right:Shape;
                public var _left:Shape;
                public var timer:Timer;

       

                private function initApp():void {
              
                var request:URLRequest = new URLRequest ("audio/");
                _sound.load(request);
                _sound.addEventListener(Event.COMPLETE,onLoad);   
               _soundChannel= _sound.play();
                _right = new Shape();
                _left = new Shape();
                addChild(_right);
                addChild(_left);
                _left.x = 200;
                _right.x= 250;
                addEventListener(Event.ENTER_FRAME, onEnterFrame);
                } 
               
                private function onEnterFrame (event:Event):void{
                _right.graphics.clear(); 
                _left.graphics.clear();
                _right.graphics.lineStyle( 0, 0x000000, 1);
                _left.graphics.lineStyle(0, 0xFFFFFF, 1);
                _right.graphics.drawRect(0,0,20,100*_soundChannel.rightPeak);
                _left.graphics.drawRect(0,0,20,100* _soundChannel.leftPeak);
                }
                
                 private function onLoad():void{ 
                enabled = true;
      }
       
                public function onStop():void{
                  _resumeTime = _soundChannel.position;
                  _soundChannel.stop();

       

      }

       

                   public function onPlay():void{ 
                   _soundChannel = _sound.play(_resumeTime);
        }           
                  private function sendInfo():void{
                      if(username.text=="" || email.text=="" || msg.text==""){
                          mx.controls.Alert.show("Please verify your form!")
                      } else {
                           contactService.send()
                      }
                  }
        
         private function thanks(evt:Event):void{
                  if(String(contactService.lastResult)=="ok") currentState = "thanks"
                  else mx.controls.Alert.show("Errors sending email!")
              }
             public function linkHandler(event:TextEvent):void {
                     
                     
                      // Open the link in a new browser window.
                      navigateToURL(new URLRequest(event.text), '_blank')
                  }

       

            private function init():void {
                      timer = new Timer(500);
                      timer.addEventListener(TimerEvent.TIMER, onTimer);
                      timer.start();
                  }

       

                  private function onTimer(evt:TimerEvent):void {
                    
                      textArea.text = " Hello welcome to the site"
                      textArea.validateNow();
                      textArea.verticalScrollPosition = textArea.maxVerticalScrollPosition;
                  }

       

       
               
                
         ]]>        
      </mx:Script>

      <mx:Move id="showeffect2" yFrom="300"/>
      <mx:Move id="hideeffect2" yBy="600"/>
      <mx:Fade id="fadeOut" duration="1000" alphaFrom="1.0" alphaTo="0.0"/>
      <mx:Fade id="fadeIn" duration="1000" alphaFrom="0.0" alphaTo="1.0"/>

       

      <mx:LinkBar color= "#FFFFFF" height="28"  dataProvider= "{tabNav}" backgroundColor="#e489cd"  borderStyle="solid" width="867" borderColor="#FFFFFF" selectionColor="0xffffff" separatorColor="0xcccccc"  rollOverColor ="0xe489cd" textRollOverColor="0xcccccc"  textSelectedColor="0x000000" x="100" y="28"/> 
          
      <mx:ViewStack id="tabNav" borderStyle="solid" width="867" height="485"  x="100" y="75">
      <mx:VBox id="Home" backgroundImage="@Embed(source='assets/StephanieHBoxmain.jpg')" showEffect="showffect2" hideEffect="hideeffect2" horizontalAlign="center" verticalAlign="middle" label="Home"  width="100%" height="100%" borderStyle="solid"  borderColor="#FFFFFF" >
            
             <mx:TextArea id="textArea" width="424" height="296" paddingTop="130" paddingBottom="100" backgroundImage="@Embed(source='assets/textareahome.jpg')"   borderColor="#FFFFFF"  borderStyle="solid" borderThickness="2" color="#FFFFFF"  backgroundColor="#e489cd"   shadowDirection="" wordWrap="true"   horizontalScrollPolicy="off"   fontSize="18" textAlign="left" verticalScrollPolicy="on" editable="false" >
                 
                 
      </mx:TextArea>

        • 1. Re: Autoscroll
          Flex harUI Adobe Employee

          Try using callLater to set verticalScrollPosition=maxVerticalScrollPosition.  I think the scrollpositions don't get updated until the end of the drawing phase.

           

          Also, it looks like you're just setting the text to a small sentence so there may not be anything to scroll

           

          Alex Harui

          Flex SDK Developer

          Adobe Systems Inc.

          Blog: http://blogs.adobe.com/aharui

          • 2. Re: Autoscroll
            webguy5612 Level 1

            I tried this and didnt work

             

            private function init():void {
                            timer = new Timer(500);
                            timer.addEventListener(TimerEvent.TIMER, onTimer);
                            timer.start();
                        }

             

                        private function onTimer(evt:TimerEvent):void {
                          
                            textArea.text = " Hello welcome to the sitedffdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdffdfdfdfdfdfdfdfdfdf"

                           ddfdddddddddddddddddddddddddddf
                            textArea.validateNow();
                            callLater(autoScrollTextArea, [textArea]);

             

                        }

             

                     private function autoScrollTextArea(target:TextArea):void{
                     target.verticalScrollPosition = target.maxVerticalScrollPosition;
                     }

             

             

             

            <mx:LinkBar color= "#FFFFFF" height="28"  dataProvider= "{tabNav}" backgroundColor="#e489cd"  borderStyle="solid" width="867" borderColor="#FFFFFF" selectionColor="0xffffff" separatorColor="0xcccccc"  rollOverColor ="0xe489cd" textRollOverColor="0xcccccc"  textSelectedColor="0x000000" x="100" y="28"/> 
                
            <mx:ViewStack id="tabNav" borderStyle="solid" width="867" height="485"  x="100" y="75">
            <mx:VBox id="Home" backgroundImage="@Embed(source='assets/HBoxmain.jpg')" showEffect="showEffect" horizontalAlign="center" verticalAlign="middle" label="Home"  width="100%" height="100%" borderStyle="solid"  borderColor="#FFFFFF" >
                  
                   <mx:TextArea id="textArea" width="424" height="296" paddingTop="250" paddingBottom="100" backgroundImage="@Embed(source='assets/textareahome.jpg')"   borderColor="#FFFFFF"  borderStyle="solid" borderThickness="2" color="#FFFFFF"  backgroundColor="#e489cd"   shadowDirection="" wordWrap="true"   horizontalScrollPolicy="off"   fontSize="18" textAlign="left" verticalScrollPolicy="on" editable="false" >
                       
                       
            </mx:TextArea>

            • 3. Re: Autoscroll
              Flex harUI Adobe Employee

              Well, maybe the timer is further interfering with the problem.  Try building a test case that doesn't use timer and huge padding values and add the text via a button click and see if the callLater trick is needed and works in that case.

               

              If you look in TextArea, you'll see that it adjusts its scroll properties "after the fact".  Another thing you could try is two callLaters.

               

              Alex Harui

              Flex SDK Developer

              Adobe Systems Inc.

              Blog: http://blogs.adobe.com/aharui