1 Reply Latest reply on Aug 13, 2009 8:56 PM by Gregory Lafrance

    Move Text from Right to Left/Marquee Effect

    us_pokiri

      Hi,

       

      I have a question....There is a text box in which I enter any text, should appear in the label above it which is placed in canvas. If I click on Button the text in the label should move from left to right.

       

      Below is the code which I wrote, although not complete...can anyone suggest/help me.....

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
      <mx:Script>
      <![CDATA[
      import mx.skins.Border;
      import mx.effects.Effect;
      import mx.events.MoveEvent;
      import mx.effects.Move;     
      private function complete():void

      {
      var i:Number;
      var newEffect:Move = new Move();
      if(btnStart.label == 'Stop'){
      btnStart.label = 'Start';
      }
      else{
      btnStart.label = 'Stop';
      mover.xFrom = 0;
      mover.xTo = 250;
      mover.play();
      }
      }          
      ]]>
      </mx:Script>
      <mx:Move id="mover" target="animate">    
      </mx:Move>
      <mx:Button x="418" y="156" label="Start"
      id="btnStart"
      click="complete()"
      />
      <mx:TextInput x="250" y="156"
      id="txtInput"/>
      <mx:Canvas id="can"
      x="250" y="119" width="160" height="29">
      <mx:Label x="0" y="10"
      id="animate" text="{txtInput.text}" width="105"/>
      </mx:Canvas>


      </mx:Application>

        • 1. Re: Move Text from Right to Left/Marquee Effect
          Gregory Lafrance Level 6

          Here is an example of using a Timer, which would be a better choice.

           

          You will need to play around with it to suit your needs.

           

          If this post answers your question or helps, please mark it as such.

           

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
            creationComplete="init();">
            <mx:Script>
              <![CDATA[
                private var timer:Timer = new Timer(100, 0);
                
                private function init():void{
                  timer.addEventListener(TimerEvent.TIMER, moveLabel);
                }
                
                private function moveLabel(evt:TimerEvent):void{
                  animate.x += 1;
                  if(animate.x == can.width){
                    animate.x = can.x;
                  }
                }
          
                private function complete():void{
                  if(btnStart.label == 'Stop'){
                    timer.stop();
                    btnStart.label = 'Start';
                  }else{
                    timer.start();
                    btnStart.label = 'Stop'; 
                  }
                }           
              ]]>
            </mx:Script>
            <mx:Canvas id="can" width="100%" height="29">
              <mx:Label x="0" y="10" id="animate" text="{txtInput.text}"/>
            </mx:Canvas>
            <mx:TextInput x="250" y="156" id="txtInput"/>
            <mx:Button x="418" y="156" label="Start" id="btnStart" click="complete()"/>
            <mx:HBox>
              <mx:Label text="Speed:"/>
              <mx:NumericStepper id="speed" minimum="1" maximum="1000" value="100" 
                change="timer.delay = speed.value;timer.stop();timer.start();"/>
            </mx:HBox>
          </mx:Application>
          
           
          

          1 person found this helpful